-
Notifications
You must be signed in to change notification settings - Fork 38
/
setupJest.js
40 lines (37 loc) · 1.03 KB
/
setupJest.js
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
// This is to handle offset values
// https://github.com/jsdom/jsdom/issues/135#issuecomment-68191941
Object.defineProperties(window.HTMLElement.prototype, {
offsetLeft: {
get() {
return parseFloat(window.getComputedStyle(this).marginLeft) || 0;
},
},
offsetTop: {
get() {
return parseFloat(window.getComputedStyle(this).marginTop) || 0;
},
},
offsetHeight: {
get() {
return parseFloat(window.getComputedStyle(this).height) || 0;
},
},
offsetWidth: {
get() {
return parseFloat(window.getComputedStyle(this).width) || 0;
},
},
});
window.HTMLElement.prototype.scrollIntoView = jest.fn();
window.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
// This is to handle getBBox on SVGElements which lack support
// You can override the mockReturnValue in your tests
window.SVGElement.prototype.getBBox = jest.fn();
window.SVGElement.prototype.getBBox.mockReturnValue({
width: 10,
height: 10,
});