-
Notifications
You must be signed in to change notification settings - Fork 0
/
withDom.js
35 lines (31 loc) · 1.01 KB
/
withDom.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
require('raf/polyfill');
/* eslint
no-console: 0,
prefer-template: 0,
prefer-destructuring: 0,
*/
if (!global.document) {
try {
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
const jsdom = require('jsdom').jsdom; // could throw
global.document = jsdom('');
global.window = global.document.defaultView;
Object.keys(global.document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
global[property] = global.document.defaultView[property];
}
});
global.navigator = {
userAgent: 'node.js',
};
} catch (e) {
// jsdom is not supported...
if (e.message === "Cannot find module 'jsdom'") {
console.error('[enzyme/withDom] Error: missing required module "jsdom"');
console.error('[enzyme/withDom] To fix this you must run:');
console.error('[enzyme/withDom] npm install jsdom --save-dev');
} else {
console.error('[enzyme withDom] ' + (e.stack || e.message));
}
}
}