test: guard browser batch mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 01:57:41 +01:00
parent 905da673e7
commit 4bf3016096

View File

@@ -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);