-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupTests.js
33 lines (27 loc) · 838 Bytes
/
setupTests.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
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { JSDOM } from 'jsdom';
// React 16 Enzyme adapter
Enzyme.configure({ adapter: new Adapter() });
// Ignore `.styl` files
require.extensions['.styl'] = () => {
return;
};
// JSDOM
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;
const copyProps = (src, target) => {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.reduce((result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(src, prop)
}), {});
Object.defineProperties(target, props);
};
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js'
};
copyProps(window, global);