-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.globalSetup.js
More file actions
53 lines (45 loc) · 1.14 KB
/
jest.globalSetup.js
File metadata and controls
53 lines (45 loc) · 1.14 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Mock global fetch
global.fetch = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve({}),
ok: true,
status: 200,
text: () => Promise.resolve(""),
})
);
// Mock process.env variables
process.env.NEXT_PUBLIC_SUPABASE_URL = "https://mock-supabase-url.com";
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY = "mock-anon-key";
// Mock localStorage
class LocalStorageMock {
constructor() {
this.store = {};
}
getItem(key) {
return this.store[key] || null;
}
setItem(key, value) {
this.store[key] = String(value);
}
removeItem(key) {
delete this.store[key];
}
clear() {
this.store = {};
}
}
global.localStorage = new LocalStorageMock();
// Mock window.matchMedia
Object.defineProperty(window, "matchMedia", {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});