enzyme: Enzyme + jsdom -> TypeError: jsdom is not a function
I am trying to get Enzyme up and running with jsdom as describe here:
http://airbnb.io/enzyme/docs/guides/jsdom.html
/* setup.js */
var jsdom = require('jsdom').jsdom;
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'
};
However, this gives the following:
TypeError: jsdom is not a function
from line 3 global.document = jsdom('');
, why? And how to resolve this?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 23 (4 by maintainers)
Got it to work with
jsdom@11.1.0
andenzyme@2.9.1
as follows:I believe you need to make ‘window’ available globally in addition to ‘document’ (shown in the above example). The below works for me:
pls update live docs to v10 😿
edit: fyi unmerged PR docs make everything work fine 🤘