-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjest.setup.ts
More file actions
56 lines (47 loc) · 1.4 KB
/
jest.setup.ts
File metadata and controls
56 lines (47 loc) · 1.4 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
import '@testing-library/jest-dom';
process.env.APP_ENV = 'test';
process.env.DEV_CACHE_ENABLED = 'true';
global.console.warn = jest.fn();
if (typeof global.setImmediate === 'undefined') {
global.setImmediate = ((fn: (...args: any[]) => void, ...args: any[]) => {
return setTimeout(fn, 0, ...args) as unknown;
}) as typeof setImmediate;
}
if (typeof global.clearImmediate === 'undefined') {
global.clearImmediate = ((id: any) => {
clearTimeout(id as unknown as ReturnType<typeof setTimeout>);
}) as typeof clearImmediate;
}
if (typeof global.structuredClone === 'undefined') {
global.structuredClone = (obj: any) => {
return JSON.parse(JSON.stringify(obj));
};
}
global.Request =
global.Request ||
class Request {
constructor(_input: string | Request, _init?: RequestInit) {}
};
global.Response =
global.Response ||
class Response {
constructor(_body?: BodyInit | null, _init?: ResponseInit) {}
};
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(),
})),
});
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));