@@ -27,6 +27,25 @@ vi.mock("./cdp.js", () => ({
|
27 | 27 | formatAriaSnapshot, |
28 | 28 | })); |
29 | 29 | |
| 30 | +type ScopedCdpClientOptions = { |
| 31 | +cdpUrl?: unknown; |
| 32 | +fn?: unknown; |
| 33 | +page?: unknown; |
| 34 | +targetId?: unknown; |
| 35 | +}; |
| 36 | + |
| 37 | +function requireScopedCdpClientOptions(): ScopedCdpClientOptions { |
| 38 | +const [call] = withPageScopedCdpClient.mock.calls; |
| 39 | +if (!call) { |
| 40 | +throw new Error("expected scoped CDP client call"); |
| 41 | +} |
| 42 | +const [options] = call; |
| 43 | +if (!options || typeof options !== "object") { |
| 44 | +throw new Error("expected scoped CDP client options"); |
| 45 | +} |
| 46 | +return options as ScopedCdpClientOptions; |
| 47 | +} |
| 48 | + |
30 | 49 | describe("pw-tools-core aria snapshot storage", () => { |
31 | 50 | beforeEach(() => { |
32 | 51 | vi.clearAllMocks(); |
@@ -53,11 +72,11 @@ describe("pw-tools-core aria snapshot storage", () => {
|
53 | 72 | expect(getPageForTargetId).toHaveBeenCalledTimes(1); |
54 | 73 | expect(ensurePageState).toHaveBeenCalledWith(page); |
55 | 74 | expect(withPageScopedCdpClient).toHaveBeenCalledTimes(1); |
56 | | -const scopedClientOptions = withPageScopedCdpClient.mock.calls[0]?.[0]; |
57 | | -expect(scopedClientOptions?.cdpUrl).toBe("http://127.0.0.1:9222"); |
58 | | -expect(scopedClientOptions?.page).toBe(page); |
59 | | -expect(scopedClientOptions?.targetId).toBe("tab-1"); |
60 | | -expect(typeof scopedClientOptions?.fn).toBe("function"); |
| 75 | +const scopedClientOptions = requireScopedCdpClientOptions(); |
| 76 | +expect(scopedClientOptions.cdpUrl).toBe("http://127.0.0.1:9222"); |
| 77 | +expect(scopedClientOptions.page).toBe(page); |
| 78 | +expect(scopedClientOptions.targetId).toBe("tab-1"); |
| 79 | +expect(typeof scopedClientOptions.fn).toBe("function"); |
61 | 80 | expect(markBackendDomRefsOnPage).toHaveBeenCalledWith({ |
62 | 81 | page, |
63 | 82 | refs: [{ ref: "ax1", backendDOMNodeId: 42 }], |
|