-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
67 lines (61 loc) · 1.63 KB
/
jest.setup.js
File metadata and controls
67 lines (61 loc) · 1.63 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Setup global mocks for tests
import '@testing-library/jest-dom'
// Mock setImmediate if not available
if (typeof global.setImmediate === 'undefined') {
global.setImmediate = (fn, ...args) => {
return setTimeout(fn, 0, ...args);
};
}
// Mock performance API
if (typeof global.performance === 'undefined') {
global.performance = {
now: () => Date.now(),
mark: jest.fn(),
measure: jest.fn(),
getEntriesByType: jest.fn(() => []),
getEntriesByName: jest.fn(() => []),
clearMarks: jest.fn(),
clearMeasures: jest.fn(),
clearResourceTimings: jest.fn(),
setResourceTimingBufferSize: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(() => true),
navigation: {
type: 0,
redirectCount: 0,
},
timing: {},
timeOrigin: Date.now(),
onresourcetimingbufferfull: null,
toJSON: () => ({}),
};
}
// Mock PerformanceObserver
if (typeof global.PerformanceObserver === 'undefined') {
global.PerformanceObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
disconnect: jest.fn(),
takeRecords: jest.fn(() => []),
}));
global.PerformanceObserver.supportedEntryTypes = [
'navigation',
'resource',
'paint',
'first-input',
'layout-shift',
'largest-contentful-paint',
'element',
];
}
// Ensure fetch is available
if (typeof global.fetch === 'undefined') {
global.fetch = jest.fn();
}
// Ensure navigator.sendBeacon is available
if (typeof navigator.sendBeacon === 'undefined') {
Object.defineProperty(navigator, 'sendBeacon', {
value: jest.fn(),
writable: true,
});
}