test: guard browser tab selection mock calls · openclaw/openclaw@0e28f4f
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 |
|---|
@@ -41,6 +41,14 @@ function fetchCallUrls(fetchMock: ReturnType<typeof vi.fn>): string[] {
|
41 | 41 | return fetchMock.mock.calls.map(([url]) => String(url)); |
42 | 42 | } |
43 | 43 | |
| 44 | +function fetchJsonCall(fetchJson: ReturnType<typeof vi.fn>, index: number): unknown[] { |
| 45 | +const call = fetchJson.mock.calls[index]; |
| 46 | +if (!call) { |
| 47 | +throw new Error(`expected fetchJson call ${index + 1}`); |
| 48 | +} |
| 49 | +return call; |
| 50 | +} |
| 51 | + |
44 | 52 | function createOldTabCleanupFetchMock( |
45 | 53 | existingTabs: ReturnType<typeof makeManagedTabsWithNew>, |
46 | 54 | params?: { rejectNewTabClose?: boolean }, |
@@ -373,13 +381,13 @@ describe("browser server-context tab selection state", () => {
|
373 | 381 | const opened = await openclaw.openTab("https://example.com"); |
374 | 382 | expect(opened.targetId).toBe("NEW"); |
375 | 383 | const jsonNewEndpoint = "http://127.0.0.1:18800/json/new?https%3A%2F%2Fexample.com"; |
376 | | -expect(fetchJson.mock.calls[0]).toEqual([ |
| 384 | +expect(fetchJsonCall(fetchJson, 0)).toEqual([ |
377 | 385 | jsonNewEndpoint, |
378 | 386 | CDP_JSON_NEW_TIMEOUT_MS, |
379 | 387 | { method: "PUT" }, |
380 | 388 | undefined, |
381 | 389 | ]); |
382 | | -expect(fetchJson.mock.calls[1]).toEqual([ |
| 390 | +expect(fetchJsonCall(fetchJson, 1)).toEqual([ |
383 | 391 | jsonNewEndpoint, |
384 | 392 | CDP_JSON_NEW_TIMEOUT_MS, |
385 | 393 | undefined, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。