-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathjest-setup.js
More file actions
61 lines (54 loc) · 1.5 KB
/
Copy pathjest-setup.js
File metadata and controls
61 lines (54 loc) · 1.5 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
import React from 'react';
import './.config/jest-setup';
import { MessageChannel } from 'worker_threads';
global.React = React;
if (!global.MessageChannel) {
global.MessageChannel = MessageChannel;
}
const mockIntersectionObserver = jest.fn().mockImplementation((callback) => ({
observe: jest.fn().mockImplementation((elem) => {
callback([{ target: elem, isIntersecting: true }]);
}),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
global.IntersectionObserver = mockIntersectionObserver;
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
Object.defineProperty(document, 'fonts', {
value: {
ready: Promise.resolve(),
load: jest.fn(() => Promise.resolve([])),
check: jest.fn(() => true),
},
writable: true,
});
HTMLCanvasElement.prototype.getContext = jest.fn(() => ({
measureText: jest.fn(() => ({ width: 0 })),
fillText: jest.fn(),
clearRect: jest.fn(),
fillRect: jest.fn(),
beginPath: jest.fn(),
moveTo: jest.fn(),
lineTo: jest.fn(),
stroke: jest.fn(),
save: jest.fn(),
restore: jest.fn(),
scale: jest.fn(),
translate: jest.fn(),
drawImage: jest.fn(),
}));
const originalGetComputedStyle = window.getComputedStyle;
window.getComputedStyle = (elt, pseudoElt) => {
const result = originalGetComputedStyle(elt, pseudoElt);
if (!result || typeof result.getPropertyValue !== 'function') {
return {
getPropertyValue: () => '',
...result,
};
}
return result;
};