Enzyme + jsdom -> TypeError: jsdom is not a function
See original GitHub issueI 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?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:23 (4 by maintainers)
Top Results From Across the Web
TypeError: require(...).jsdom is not a function - Stack Overflow
Try using the following, var jsdom = require('jsdom'); const { JSDOM } = jsdom; const { document } = (new JSDOM('')).window; global.document ...
Read more >Using enzyme with JSDOM - GitHub Pages
Since enzyme's mount API requires a DOM, JSDOM is required in order to use mount if you are not already in a browser...
Read more >DOM Manipulation - Jest
DOM Manipulation. Another class of functions that is often considered difficult to test is code that directly manipulates the DOM.
Read more >Setup - Testing Library
React Testing Library does not require any configuration to be used. However, ... You can enable jsdom globally by editing jest.config.js :.
Read more >Jsdom NPM package broken | Velo by Wix
const jsdom = require("jsdom");. when trying this i get. Uncaught (in promise) TypeError: (0 , _jsdom.require) is not a function.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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: