Coder Social home page Coder Social logo

Cleanup globals after tests about tests HOT 9 CLOSED

geowarin avatar geowarin commented on September 22, 2024
Cleanup globals after tests

from tests.

Comments (9)

zackify avatar zackify commented on September 22, 2024

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!

from tests.

geowarin avatar geowarin commented on September 22, 2024

Thanks for your quick reply!
You are right, the tests run in node 4.

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.
So in the browser, axios is using XMLHttpRequest and in node, they use the http library.
If you look at their code, they test for presence of XMLHttpRequest, which jsdom puts in the global.

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.

from tests.

geowarin avatar geowarin commented on September 22, 2024

I you want to have a look at the project I'm working on:

from tests.

zackify avatar zackify commented on September 22, 2024

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.

from tests.

zackify avatar zackify commented on September 22, 2024

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!

from tests.

zackify avatar zackify commented on September 22, 2024

@geowarin can you specify what you need done? I'm going to close this in a few days if there's no reply

from tests.

geowarin avatar geowarin commented on September 22, 2024

Hi @zackify !
I have no perfect solution for the moment.
Not being tied to a testing framework means that you have no hook to do proper cleaning.

Maybe you could optionally let the user do the jsdom init?

#9 is fantastic!
I'll push the changeValues middleware as soon as you review #19 😄

from tests.

geowarin avatar geowarin commented on September 22, 2024

I've just seen #14. It seems that we are moving towards an optional jsdom init, then.

from tests.

zackify avatar zackify commented on September 22, 2024

I'm thinking even though it's as easy as not including the dom.js file, I
might make this a different file "legit-tests/nodom" or something?
On Wed, Sep 23, 2015 at 02:49 Geoffroy Warin [email protected]
wrote:

I've just seen #14 #14. It
seems that we are moving towards an optional jsdom init, then.


Reply to this email directly or view it on GitHub
#11 (comment).

from tests.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.