-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathsetupTests.ts
More file actions
97 lines (86 loc) · 2.1 KB
/
setupTests.ts
File metadata and controls
97 lines (86 loc) · 2.1 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { configure } from '@testing-library/react';
import '@testing-library/jest-dom';
import 'jest-canvas-mock';
// Wait time needed
const TIMEOUT = 300000;
// mocks open
global.open = jest.fn();
global.fetch = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve(() => 'xxx'),
arrayBuffer: () => Promise.resolve(() => 'yyy'),
}),
) as jest.Mock;
window.URL.createObjectURL = jest.fn();
// mocks ResizeObserver
window.ResizeObserver = jest.fn(() => ({
observe: () => {},
unobserve: () => {},
disconnect: () => {},
}));
// mocks IntersectionObserver
(window as any).IntersectionObserver = jest.fn(() => ({
root: null,
rootMargin: '0px',
scrollMargin: '0px',
thresholds: [],
takeRecords: () => [],
observe: () => {},
unobserve: () => {},
disconnect: () => {},
})) as any;
// mocks createSVGPoint
Object.defineProperty(global.SVGSVGElement.prototype, 'createSVGPoint', {
writable: true,
value: jest.fn().mockImplementation(() => ({
x: 0,
y: 0,
matrixTransform: jest.fn().mockImplementation(() => ({
x: 0,
y: 0,
})),
})),
});
// mocks getBBox on SVGTextElement
(global.SVGElement.prototype as any).getBBox = () => {
return {
x: 0,
y: 0,
width: 30,
height: 15,
bottom: 0,
left: 0,
right: 0,
top: 0,
toJSON: () => '',
};
};
// Mocks the window.matchMedia function used in useBreakpoint hook
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 Web Animations API
Object.defineProperty(Element.prototype, 'animate', {
writable: true,
value: jest.fn().mockImplementation(() => ({
play: jest.fn(),
pause: jest.fn(),
finish: jest.fn(),
cancel: jest.fn(),
reverse: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
jest.setTimeout(TIMEOUT);