-
Notifications
You must be signed in to change notification settings - Fork 27
/
setupTests.ts
85 lines (74 loc) · 1.83 KB
/
setupTests.ts
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
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.IntersectionObserver = jest.fn(() => ({
root: null,
rootMargin: '0',
thresholds: [],
takeRecords: () => [],
observe: () => {},
unobserve: () => {},
disconnect: () => {}
}));
// 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()
}))
});
jest.setTimeout(TIMEOUT);
// speeds up *ByRole queries a bit
// https://github.com/testing-library/dom-testing-library/issues/552
configure({ defaultHidden: true });