Hi. I've loaded jsdom like this:
jsdom.env({
html: '<html><body></body</html>',
done: () => runTests()
});
And just to be through I tried const document = jsdom.env... and const window = jsdom.env ...
The runTests method had this statement: mount(
But ever time I run it, I get the following error: "It looks like you called mount() without a jsdom document being loaded. ' + 'Make sure to only use mount() inside of a `describeWithDOM(...)"
Your documentation says I don't need to use describeWithDOM if I'm not using mocha.
I figured it out. You can close this or leave it to help others. What I needed to do was load jsdom as a global object in my node test script:
import jsdom as 'jsdom';
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>');
const win = doc.defaultView;
global.document = doc;
global.window = win;
It might be good to post these things on stack overflow as it's a first resource for most developers these days.
I consider Stack Overflow a good place to find help for something you want to do with the library which is not a shortcoming of the library itself, but your own knowledge.
To me this seems like a legit question to post as an issue, because the library is indeed tied to Mocha, which might be something that should be fixed or at least documented.
"the library is indeed tied to Mocha"
The documentation implies that you can use it without mocha. Which is what I do, so far without problems, except for not knowing how to get jsdom working. Now that I've done that, everything is going well.
@silvenon @mgeduld We agree this is a legitimate issue. We are working on a 2.0 release that will gut out all ties to mocha, and also include guides/documentation on getting enzyme up and running in every popular testing framework. I apologize for the issues thus far, but I'm glad you've gotten it up and running!
@mgeduld your jsdom hack worked 馃憣 for me, thanks!
Yay!
Not sure why, but your code wasn't working for me.
My version:
import {JSDOM} from 'jsdom'
const dom = new JSDOM('<!doctype html><html><body></body></html>')
global.window = dom.window
global.document = dom.window.document
Most helpful comment
I consider Stack Overflow a good place to find help for something you want to do with the library which is not a shortcoming of the library itself, but your own knowledge.
To me this seems like a legit question to post as an issue, because the library is indeed tied to Mocha, which might be something that should be fixed or at least documented.