test: guard browser gateway mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 01:37:57 +01:00
parent e23d7db1f1
commit 83154d8470
3 changed files with 12 additions and 5 deletions

View File

@@ -76,7 +76,7 @@ function invokeParams(nodeRegistry: ReturnType<typeof createContext>) {
}
function firstRespondCall(respond: ReturnType<typeof vi.fn>): RespondCall {
const call = respond.mock.calls[0] as RespondCall | undefined;
const [call] = respond.mock.calls as RespondCall[];
if (!call) {
throw new Error("expected respond call");
}

View File

@@ -100,9 +100,12 @@ async function browserRequestStatus(): Promise<unknown> {
req: { type: "req", id: "req-1", method: "browser.request" },
isWebchatConnect: () => false,
});
const call = respond.mock.calls[0];
expect(call?.[0]).toBe(true);
return call?.[1];
const [call] = respond.mock.calls;
if (!call) {
throw new Error("expected browser request response");
}
expect(call[0]).toBe(true);
return call[1];
}
describe("browser.request local control state", () => {

View File

@@ -62,7 +62,11 @@ describe("browser.request local timeout", () => {
});
expect(withTimeoutMock).toHaveBeenCalledTimes(1);
const [dispatchTask, timeoutMs, timeoutLabel] = withTimeoutMock.mock.calls[0];
const [call] = withTimeoutMock.mock.calls;
if (!call) {
throw new Error("expected withTimeout call");
}
const [dispatchTask, timeoutMs, timeoutLabel] = call;
expect(dispatchTask).toBeTypeOf("function");
expect(timeoutMs).toBe(4321);
expect(timeoutLabel).toBe("browser request");