-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
53 lines (47 loc) · 1.37 KB
/
jest.setup.js
File metadata and controls
53 lines (47 loc) · 1.37 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
// Learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
// Mock environment variables
process.env.GROQ_API_KEY = 'test-api-key';
// 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(),
})),
});
// Mock localStorage with Map-based storage
const createLocalStorageMock = () => {
const store = new Map();
return {
getItem: (key) => store.get(key) || null,
setItem: (key, value) => store.set(key, String(value)),
removeItem: (key) => store.delete(key),
clear: () => store.clear(),
};
};
global.localStorage = createLocalStorageMock();
// Mock File API for browser file uploads
class MockFile {
constructor(bits, name, options = {}) {
this.name = name;
this.size = bits.reduce((acc, bit) => {
if (bit instanceof ArrayBuffer) {
return acc + bit.byteLength;
}
if (typeof bit === 'string') {
return acc + bit.length;
}
return acc + (bit.length || 0);
}, 0);
this.type = options.type || '';
this.lastModified = options.lastModified || Date.now();
}
}
global.File = MockFile;