Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you use mount/jsdom without mocha? #75

Closed
mgeduld opened this issue Dec 15, 2015 · 8 comments
Closed

How do you use mount/jsdom without mocha? #75

mgeduld opened this issue Dec 15, 2015 · 8 comments

Comments

@mgeduld
Copy link

mgeduld commented Dec 15, 2015

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.

@mgeduld
Copy link
Author

mgeduld commented Dec 15, 2015

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;

@blainekasten
Copy link
Contributor

It might be good to post these things on stack overflow as it's a first resource for most developers these days.

@silvenon
Copy link
Contributor

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.

@mgeduld
Copy link
Author

mgeduld commented Dec 16, 2015

"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.

@lelandrichardson
Copy link
Collaborator

@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!

@defvol
Copy link

defvol commented Apr 21, 2016

@mgeduld your jsdom hack worked 👌 for me, thanks!

@mgeduld
Copy link
Author

mgeduld commented Apr 22, 2016

Yay!

@aymericbouzy
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants