diff --git a/CLAUDE.md b/CLAUDE.md index 0181c212..0a6bef50 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -78,6 +78,7 @@ Three-tier strategy. See [docs/testing-strategy.md](docs/testing-strategy.md) fo - Use `selectFeedInSidebar(page, name)` from `fixtures.ts` — it handles opening the sidebar on mobile. **happy-dom gotchas**: +- happy-dom is a real resource loader: a `` or `'; + await settle(); + + expect(request).not.toHaveBeenCalled(); + }); +}); diff --git a/tests/pages/billing-success.test.tsx b/tests/pages/billing-success.test.tsx index ca5e31de..dc3add25 100644 --- a/tests/pages/billing-success.test.tsx +++ b/tests/pages/billing-success.test.tsx @@ -1,4 +1,4 @@ -import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, expect, vi, beforeEach, afterEach, type Mock } from "vitest"; import { render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { MemoryRouter } from "react-router"; @@ -33,6 +33,21 @@ function renderWithRoute(path: string) { } describe("BillingSuccess page", () => { + // Rendering with a session_id makes the page request the license for that + // session on mount. Tests that only assert copy never stubbed fetch, so + // happy-dom opened a real socket to localhost:3000 on every run. A default + // pending stub keeps the page in its initial state, which is what those + // tests were observing anyway; tests that need a response override it. + beforeEach(() => { + vi.stubGlobal( + "fetch", + vi.fn(() => new Promise(() => {})), + ); + }); + afterEach(() => { + vi.unstubAllGlobals(); + }); + it("renders a confirmation heading", () => { renderWithRoute("/billing/success"); expect( @@ -48,6 +63,12 @@ describe("BillingSuccess page", () => { expect( screen.getByRole("button", { name: /save/i }), ).toBeInTheDocument(); + // The page asks the server for this session's license rather than + // waiting for the user to paste — the input is the fallback. + const calls = (globalThis.fetch as unknown as Mock).mock.calls as Array< + [RequestInfo | URL, RequestInit?] + >; + expect(calls.some(([url]) => String(url).includes("/api/license/retrieve"))).toBe(true); }); it("does NOT render the session id as page chrome on the polling-state happy path", async () => { diff --git a/vitest.config.js b/vitest.config.js index e8d38e2c..59673d09 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -10,6 +10,21 @@ export default defineConfig({ }, test: { environment: "happy-dom", + // happy-dom is a real resource loader: a or + //