/
jest.setup.js
98 lines (83 loc) · 2.36 KB
/
jest.setup.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
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
98
/**
* @author Adam Charron <adam.c@vanillaforums.com>
* @copyright 2009-2021 Vanilla Forums Inc.
* @license gpl-2.0-only
*/
const { EMPTY_RECT } = require("@vanilla/react-utils");
const enzyme = require("enzyme");
const Adapter = require("enzyme-adapter-react-16");
const registerRequireContextHook = require("babel-plugin-require-context-hook/register");
require("@testing-library/jest-dom");
enzyme.configure({ adapter: new Adapter() });
registerRequireContextHook();
// Mock resize observer
global.ResizeObserver = class ResizeObserver {
observe() {
// do nothing
}
unobserve() {
// do nothing
}
disconnect() {
// do nothing
}
};
global.IntersectionObserver = class IntersectionObserver {
constructor() {}
observe() {
// do nothing
}
disconnect() {
// do nothing
}
unobserve() {
// do nothing
}
};
// Mock DataTransfer, commonly used in copy/paste and drag/drop operations.
global.DataTransfer = class DataTransfer {
constructor() {
this.data = new Map();
}
getData = (key) => this.data.get(key);
setData = (key, val) => this.data.set(key, val);
};
global.Range.prototype.getBoundingClientRect = () => {
// Make these a bit different from the empty rect so that things checking that something actually rendered
// see an actual rect. Some of our code has bailouts on an empty rect.
return { ...EMPTY_RECT, top: 1, left: 1, width: 20, height: 20 };
};
const originalWarn = console.warn;
global.console.warn = (...args) => {
if (args[0]?.startsWith("@reach")) {
// Suppress reach style warnings.
return;
}
if (args[0]?.includes("componentWillReceiveProps has been renamed")) {
// React router 5 warnings.
return;
}
originalWarn(...args);
};
const originalError = console.error;
global.console.error = (...args) => {
for (const arg of args) {
if (typeof arg === "string" && arg.includes("state update on an unmounted component")) {
return;
}
}
originalError(...args);
};
// Stub in require.context (does nothing).
if (!global.require) {
global.require = () => {};
}
global.require.context = (function () {
function req() {}
req.keys = function () {
return [];
};
req.resolve = function () {};
return req;
})();
jest.setTimeout(10000);