diff --git a/frontend/src/setupTests.ts b/frontend/src/setupTests.ts index d0de870..3de2908 100644 --- a/frontend/src/setupTests.ts +++ b/frontend/src/setupTests.ts @@ -1 +1,14 @@ 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 })), + ), + ); +}); diff --git a/frontend/vitest.config.ts b/frontend/vitest.config.ts index f77f4f2..12c61cb 100644 --- a/frontend/vitest.config.ts +++ b/frontend/vitest.config.ts @@ -8,6 +8,11 @@ export default defineConfig({ }, test: { environment: "jsdom", + environmentOptions: { + jsdom: { + url: "http://localhost:3000", + }, + }, globals: true, testTimeout: 10_000, setupFiles: ["./src/setupTests.ts"],