forked from multiprocessio/datastation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testsetup.js
62 lines (53 loc) · 1.39 KB
/
testsetup.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
const { act } = require('react-dom/test-utils');
const { wait } = require('./shared/promise');
require('./shared/polyfill');
// https://enzymejs.github.io/enzyme/docs/guides/jsdom.html
const { JSDOM } = require('jsdom');
const { configure } = require('enzyme');
const Adapter = require('@wojtekmaj/enzyme-adapter-react-17');
configure({ adapter: new Adapter() });
const jsdom = new JSDOM('<!doctype html><html><body></body></html>', {
url: 'http://localhost/?projectId=test',
});
const { window } = jsdom;
class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
window.ResizeObserver = ResizeObserver;
function copyProps(src, target) {
Object.defineProperties(target, {
...Object.getOwnPropertyDescriptors(src),
...Object.getOwnPropertyDescriptors(target),
});
}
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};
global.requestAnimationFrame = function (callback) {
return setTimeout(callback, 0);
};
global.cancelAnimationFrame = function (id) {
clearTimeout(id);
};
copyProps(window, global);
window.fetch = () => {
return Promise.resolve({
text() {
return Promise.resolve(null);
},
json() {
return Promise.resolve(null);
},
});
};
global.componentLoad = async function (component) {
await wait(1000);
await act(async () => {
await wait(0);
component.update();
});
};