From 4bf301609650560b79ecd7a4e17c2404d8a3ddfd Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 01:57:41 +0100 Subject: [PATCH] test: guard browser batch mock calls --- .../pw-tools-core.interactions.batch.test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/extensions/browser/src/browser/pw-tools-core.interactions.batch.test.ts b/extensions/browser/src/browser/pw-tools-core.interactions.batch.test.ts index 3a0ce7c0ec9..7beff563b24 100644 --- a/extensions/browser/src/browser/pw-tools-core.interactions.batch.test.ts +++ b/extensions/browser/src/browser/pw-tools-core.interactions.batch.test.ts @@ -38,6 +38,17 @@ vi.mock("./pw-tools-core.snapshot.js", () => ({ const { batchViaPlaywright } = await import("./pw-tools-core.interactions.js"); +function firstEvaluateCall(): [unknown, { fnBody?: string; timeoutMs?: number }] { + if (!page) { + throw new Error("expected test page"); + } + const [call] = page.evaluate.mock.calls; + if (!call) { + throw new Error("expected page.evaluate call"); + } + return call as [unknown, { fnBody?: string; timeoutMs?: number }]; +} + describe("batchViaPlaywright", () => { beforeEach(() => { vi.clearAllMocks(); @@ -56,7 +67,7 @@ describe("batchViaPlaywright", () => { }); expect(result).toEqual({ results: [{ ok: true }] }); - const [evaluateFn, evaluateOptions] = page?.evaluate.mock.calls[0] ?? []; + const [evaluateFn, evaluateOptions] = firstEvaluateCall(); expect(typeof evaluateFn).toBe("function"); expect(evaluateOptions?.fnBody).toBe("() => 1"); expect(evaluateOptions?.timeoutMs).toBe(4500);