-
Notifications
You must be signed in to change notification settings - Fork 7
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
Cleanup globals after tests #11
Comments
I had noticed a few of these issues when I made #6. I don't see what problems would be caused with global variables, at least so far. The only things that are global is React, window, and document. So I'm a little unsure about what you want cleaned up after a test runs. As for the canUseDom, I found it's the only way when using jsdom inside of the library because for some reason imports aren't always loaded in order (or something else weird is happening). This library is meant to run inside of node v4+ not in the browser. Hope that helped answer some things. Btw, thank you so much for wanting to use this library :) It makes testing so much faster for me, and I would gladly add anything to it that would help you too! |
Thanks for your quick reply! However, I'm using axios to make http requests for example and I'd like to test requests made within my app in my test suite too. It's totally possible to work around this by unsetting specific globals for certain tests but it does not feel like the perfect solution intellectually. |
I you want to have a look at the project I'm working on:
|
Thanks for the links to your tests I see what you mean. The only thing I'm confused on now is that in the test you're doing to make an http request you're not including legit tests but I'm guessing it was included in another test and the globals are still there? If so then I see the problem. |
Also, I think you'll like what I just added #9 :) Edit: that changeValues function looks really nice, you should send a PR with it as bundled middleware! |
@geowarin can you specify what you need done? I'm going to close this in a few days if there's no reply |
I've just seen #14. It seems that we are moving towards an optional jsdom init, then. |
I'm thinking even though it's as easy as not including the dom.js file, I
|
Hi there!
Thank you so much for the lib, I love the middleware idea and I'm planning to use it on a massive scale.
In the meantime, I noticed some problems in my test suite because globals are not cleaned up after a test.
The problem is that some libraries test for the presence of window or document to know if they run in node or in the browser.
If you take a look at what mocha-jsdom does : they have a hook to restore the global values after each test.
Another problem is react testing the ExecutionEnvironment.canUseDOM boolean.
In my experience, you can either put this to true like you did or try to initialise a fake DOM before all your test suites (with mocha --require flag for instance).
Mocha-jsdom fails miserably at this because in case of nested component re-rendering, this flag will be reinitialised.
I just wanted to open the discussion to know if you have any insight about this.
The text was updated successfully, but these errors were encountered: