forked from enzymejs/enzyme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
withDom.js
26 lines (24 loc) · 830 Bytes
/
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
if (!global.document) {
try {
const jsdom = require('jsdom').jsdom; // could throw
global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
global[property] = 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));
}
}
}