diff --git a/web/vitest.setup.ts b/web/vitest.setup.ts index b945f675f7..6211fcd2f4 100644 --- a/web/vitest.setup.ts +++ b/web/vitest.setup.ts @@ -74,6 +74,18 @@ if (typeof globalThis.IntersectionObserver === 'undefined') { } } +// Mock global fetch to prevent happy-dom from making real network calls +// (which would cause ECONNREFUSED errors against localhost:5001). +// Individual tests can still override via vi.spyOn(globalThis, 'fetch') or reassignment. +globalThis.fetch = vi.fn(() => + Promise.resolve( + new Response(JSON.stringify({}), { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }), + ), +) as unknown as typeof fetch + afterEach(async () => { // Wrap cleanup in act() to flush pending React scheduler work // This prevents "window is not defined" errors from React 19's scheduler