From 3ced187aaa45b1c2bb7975e2815cc6837e62f67d Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 19 Mar 2026 16:07:56 +0000 Subject: [PATCH] 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) --- frontend/src/setupTests.ts | 13 +++++++++++++ frontend/vitest.config.ts | 5 +++++ 2 files changed, 18 insertions(+) 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"],