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:
@@ -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 })),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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"],
|
||||
|
||||
Reference in New Issue
Block a user