test: guard channel provider helpers

This commit is contained in:
Peter Steinberger
2026-05-11 19:41:19 +01:00
parent a091a77dbd
commit 0793775a66
3 changed files with 13 additions and 6 deletions

View File

@@ -86,7 +86,9 @@ async function waitForFakeSocket(): Promise<FakeWebSocketInstance> {
let socket: FakeWebSocketInstance | undefined;
await vi.waitFor(() => {
socket = FakeWebSocket.instances[0];
expect(socket).toBeDefined();
if (!socket) {
throw new Error("expected session to create a websocket");
}
});
if (!socket) {
throw new Error("expected session to create a websocket");

View File

@@ -79,9 +79,11 @@ function statusPatches(source: MockCallSource): Record<string, unknown>[] {
}
function expectPollingConnectedPatch(patch: Record<string, unknown> | undefined): void {
expect(patch).toBeDefined();
expect(patch?.connected).toBe(true);
expect(patch?.mode).toBe("polling");
if (!patch) {
throw new Error("Expected polling connected patch");
}
expect(patch.connected).toBe(true);
expect(patch.mode).toBe("polling");
}
function makeBot() {

View File

@@ -95,8 +95,11 @@ function mockStringMessages(mocked: unknown): string[] {
function mockCallArg(mocked: unknown, callIndex: number, argIndex: number): unknown {
const calls = (mocked as { mock?: { calls?: unknown[][] } }).mock?.calls;
expect(calls?.[callIndex]).toBeDefined();
return calls?.[callIndex]?.[argIndex];
const call = calls?.[callIndex];
if (!call) {
throw new Error(`Expected mock call at index ${callIndex}`);
}
return call[argIndex];
}
async function expectPathMissing(targetPath: string): Promise<void> {