fix: mock fetch in test setup to suppress URL parse errors in jsdom

Also set jsdom base URL to http://localhost:3000 in vitest config.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dave
2026-03-19 16:07:56 +00:00
parent 64f73e24bf
commit 3ced187aaa
2 changed files with 18 additions and 0 deletions

View File

@@ -1 +1,14 @@
import "@testing-library/jest-dom"; import "@testing-library/jest-dom";
import { beforeEach, vi } from "vitest";
// Provide a default fetch mock so components that call API endpoints on mount
// don't throw URL-parse errors in the jsdom test environment. Tests that need
// specific responses should mock the relevant `api.*` method as usual.
beforeEach(() => {
vi.stubGlobal(
"fetch",
vi.fn(() =>
Promise.resolve(new Response(JSON.stringify({}), { status: 200 })),
),
);
});

View File

@@ -8,6 +8,11 @@ export default defineConfig({
}, },
test: { test: {
environment: "jsdom", environment: "jsdom",
environmentOptions: {
jsdom: {
url: "http://localhost:3000",
},
},
globals: true, globals: true,
testTimeout: 10_000, testTimeout: 10_000,
setupFiles: ["./src/setupTests.ts"], setupFiles: ["./src/setupTests.ts"],