From 83154d847039a4dcda5f1fd89b0085ebcdaa69a5 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 01:37:57 +0100 Subject: [PATCH] test: guard browser gateway mock calls --- .../gateway/browser-request.profile-from-body.test.ts | 2 +- .../gateway/browser-request.shared-control-state.test.ts | 9 ++++++--- .../browser/src/gateway/browser-request.timeout.test.ts | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/extensions/browser/src/gateway/browser-request.profile-from-body.test.ts b/extensions/browser/src/gateway/browser-request.profile-from-body.test.ts index 757bfffbc44..0051029047d 100644 --- a/extensions/browser/src/gateway/browser-request.profile-from-body.test.ts +++ b/extensions/browser/src/gateway/browser-request.profile-from-body.test.ts @@ -76,7 +76,7 @@ function invokeParams(nodeRegistry: ReturnType) { } function firstRespondCall(respond: ReturnType): 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"); } diff --git a/extensions/browser/src/gateway/browser-request.shared-control-state.test.ts b/extensions/browser/src/gateway/browser-request.shared-control-state.test.ts index 55e9086b4e3..eac0117ea37 100644 --- a/extensions/browser/src/gateway/browser-request.shared-control-state.test.ts +++ b/extensions/browser/src/gateway/browser-request.shared-control-state.test.ts @@ -100,9 +100,12 @@ async function browserRequestStatus(): Promise { 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", () => { diff --git a/extensions/browser/src/gateway/browser-request.timeout.test.ts b/extensions/browser/src/gateway/browser-request.timeout.test.ts index bb5b6511360..0714cf0d237 100644 --- a/extensions/browser/src/gateway/browser-request.timeout.test.ts +++ b/extensions/browser/src/gateway/browser-request.timeout.test.ts @@ -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");