diff --git a/extensions/browser/src/browser/server-context.tab-selection-state.test.ts b/extensions/browser/src/browser/server-context.tab-selection-state.test.ts index 0331625d47f..2ea550fa203 100644 --- a/extensions/browser/src/browser/server-context.tab-selection-state.test.ts +++ b/extensions/browser/src/browser/server-context.tab-selection-state.test.ts @@ -6,6 +6,7 @@ vi.hoisted(() => { }); import "./server-context.chrome-test-harness.js"; +import { CDP_JSON_NEW_TIMEOUT_MS } from "./cdp-timeouts.js"; import * as cdpHelpersModule from "./cdp.helpers.js"; import * as cdpModule from "./cdp.js"; import { InvalidBrowserNavigationUrlError } from "./navigation-guard.js"; @@ -36,13 +37,14 @@ function seedRunningProfileState( async function expectOldManagedTabClose(fetchMock: ReturnType): Promise { await vi.waitFor(() => { - expect(fetchMock).toHaveBeenCalledWith( - expect.stringContaining("/json/close/OLD1"), - expect.any(Object), - ); + expect(fetchCallUrls(fetchMock).some((url) => url.includes("/json/close/OLD1"))).toBe(true); }); } +function fetchCallUrls(fetchMock: ReturnType): string[] { + return fetchMock.mock.calls.map(([url]) => String(url)); +} + function createOldTabCleanupFetchMock( existingTabs: ReturnType, params?: { rejectNewTabClose?: boolean }, @@ -192,10 +194,7 @@ describe("browser server-context tab selection state", () => { const opened = await openManagedTabWithRunningProfile({ fetchMock }); expect(opened.targetId).toBe("NEW"); await expectOldManagedTabClose(fetchMock); - expect(fetchMock).not.toHaveBeenCalledWith( - expect.stringContaining("/json/close/NEW"), - expect.anything(), - ); + expect(fetchCallUrls(fetchMock).some((url) => url.includes("/json/close/NEW"))).toBe(false); }); it("does not fail tab open when managed-tab cleanup list fails", async () => { @@ -253,10 +252,7 @@ describe("browser server-context tab selection state", () => { const opened = await openclaw.openTab("http://127.0.0.1:3009"); expect(opened.targetId).toBe("NEW"); - expect(fetchMock).not.toHaveBeenCalledWith( - expect.stringContaining("/json/close/"), - expect.anything(), - ); + expect(fetchCallUrls(fetchMock).some((url) => url.includes("/json/close/"))).toBe(false); }); it("does not block openTab on slow best-effort cleanup closes", async () => { @@ -321,19 +317,18 @@ describe("browser server-context tab selection state", () => { const opened = await openclaw.openTab("https://example.com"); expect(opened.targetId).toBe("NEW"); - expect(fetchJson).toHaveBeenNthCalledWith( - 1, - expect.stringContaining("/json/new"), - expect.any(Number), + const jsonNewEndpoint = "http://127.0.0.1:18800/json/new?https%3A%2F%2Fexample.com"; + expect(fetchJson.mock.calls[0]).toEqual([ + jsonNewEndpoint, + CDP_JSON_NEW_TIMEOUT_MS, { method: "PUT" }, undefined, - ); - expect(fetchJson).toHaveBeenNthCalledWith( - 2, - expect.stringContaining("/json/new"), - expect.any(Number), + ]); + expect(fetchJson.mock.calls[1]).toEqual([ + jsonNewEndpoint, + CDP_JSON_NEW_TIMEOUT_MS, undefined, undefined, - ); + ]); }); });