forked from staylor/react-helmet-async
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
45 lines (37 loc) · 1.05 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
import 'raf/polyfill';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import ReactDOM from 'react-dom';
import { clearInstances } from './src/HelmetData';
configure({ adapter: new Adapter() });
const { JSDOM } = require('jsdom');
const jsdom = new JSDOM('<!doctype html><html><body><div id="mount"></div></body></html>', {
url: 'https://nytimes.com',
});
const { window } = jsdom;
function 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);
const mount = document.getElementById('mount');
beforeEach(() => {
document.head.innerHTML = '';
});
afterEach(() => {
ReactDOM.unmountComponentAtNode(mount);
clearInstances();
});