-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvitest.setup.ts
39 lines (35 loc) · 982 Bytes
/
vitest.setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { vi } from "vitest";
process.env.HASURA_URL = "http://hasura/v1/graphql";
process.env.NEXT_PUBLIC_HASURA_URL = "http://localhost:8080/v1/graphql";
vi.mock("next/navigation", async () => {
const originalModule = await vi.importActual("react");
return {
...originalModule,
useRouter: () => ({
push: () => {},
refresh: () => {},
}),
};
});
vi.mock("react", async () => {
const testCache = <T extends (...args: Array<unknown>) => unknown>(func: T) =>
func;
const originalModule = await vi.importActual("react");
return {
...originalModule,
cache: testCache,
};
});
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});