GithubHelp home page GithubHelp logo

Comments (6)

lelandrichardson avatar lelandrichardson commented on April 28, 2024

@KnisterPeter since you are using a browser based test runner, you should be able to use enzyme without needing jsdom. As a result, can you try running your tests without using the describeWithDOM helper?

from enzyme.

KnisterPeter avatar KnisterPeter commented on April 28, 2024

We are running our tests with wallabyjs in node. So this is not a browser based test. Sorry for missing that detail.

from enzyme.

lelandrichardson avatar lelandrichardson commented on April 28, 2024

@KnisterPeter oops. No, that's my fault. I thought I knew what wallaby.js was, but apparently I didn't.

I'm not sure what the error is then. The error you're getting is an indication of mocha-jsdom attempting to create a window and document object, but finding them already on the global namespace and thus throwing. Does wallaby.js perhaps inject some browser-like APIs into the global namespace?

from enzyme.

KnisterPeter avatar KnisterPeter commented on April 28, 2024

I don't think so. Maybe its 'watching' your code and then reevaluate or something like this.
Wouldn't it be possible for enzyme to add an option for 'skipWindowCheck' in the describeWithDOM method?

from enzyme.

ArtemGovorov avatar ArtemGovorov commented on April 28, 2024

@lelandrichardson wallaby.js supports both browser and node testing.

The issue is that mocha-jsdom deletes global.window in mocha after hook, and wallaby.js (as a continuous test runner) can't guarantee that the hook will be invoked.

For example, if you have a few async tests, and they are running, and you change your code at the same time, wallaby.js will force cancel the previous run, and the hook may not be executed (under some circumstances). Also some code changes may require wallaby to force cancel the run, for example introducing an infinite loop in your code or high level test structure errors. Because wallaby runs your tests as you type, the likelihood of such changes is much higher than when you run your tests occasionally with plain mocha.

mocha-jsdom exports a function that supports a few options (as @KnisterPeter mentioned skipWindowCheck is one of them that could help) and enzyme could support passing those options to it.

A cleaner solution only requiring a small addition to the wallaby config file would be to use wallaby.js teardown function to just delete the window object if it wasn't deleted by the after hook. The function is guaranteed to be called no matter what kind of changes wallaby.js had to deal with (unless the changes require to recycle node.js process, in which case you don't have to care about the window object anyway).

module.exports = function () {
  return {
    ...
    teardown: function(){
      delete global.window;
    }
  };
};

There's another solution which can make wallaby.js work just like other test runners (kill node.js process after tests are finished) with the workers.recycle option. Even though wallaby will still be faster then other runners (because it'll execute only affected tests, not all tests), you'll notice that tests are running a bit slower than without the option. I only recommend using the option when you really need that kind of a separate process isolation for each test run and can't really allow wallaby to reuse node processes.

from enzyme.

KnisterPeter avatar KnisterPeter commented on April 28, 2024

Thanks @ArtemGovorov
I've created a pull request with the optional options for jsdom but I will give the teardown a try as well.

from enzyme.

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.