test: guard browser batch mock calls · openclaw/openclaw@4bf3016
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
File tree
extensions/browser/src/browser
| Original file line number | Diff line number | Diff line change |
|---|
@@ -38,6 +38,17 @@ vi.mock("./pw-tools-core.snapshot.js", () => ({
|
38 | 38 | |
39 | 39 | const { batchViaPlaywright } = await import("./pw-tools-core.interactions.js"); |
40 | 40 | |
| 41 | +function firstEvaluateCall(): [unknown, { fnBody?: string; timeoutMs?: number }] { |
| 42 | +if (!page) { |
| 43 | +throw new Error("expected test page"); |
| 44 | +} |
| 45 | +const [call] = page.evaluate.mock.calls; |
| 46 | +if (!call) { |
| 47 | +throw new Error("expected page.evaluate call"); |
| 48 | +} |
| 49 | +return call as [unknown, { fnBody?: string; timeoutMs?: number }]; |
| 50 | +} |
| 51 | + |
41 | 52 | describe("batchViaPlaywright", () => { |
42 | 53 | beforeEach(() => { |
43 | 54 | vi.clearAllMocks(); |
@@ -56,7 +67,7 @@ describe("batchViaPlaywright", () => {
|
56 | 67 | }); |
57 | 68 | |
58 | 69 | expect(result).toEqual({ results: [{ ok: true }] }); |
59 | | -const [evaluateFn, evaluateOptions] = page?.evaluate.mock.calls[0] ?? []; |
| 70 | +const [evaluateFn, evaluateOptions] = firstEvaluateCall(); |
60 | 71 | expect(typeof evaluateFn).toBe("function"); |
61 | 72 | expect(evaluateOptions?.fnBody).toBe("() => 1"); |
62 | 73 | expect(evaluateOptions?.timeoutMs).toBe(4500); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。