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

Resetting js dom multiple times during mocha tests #20

Open
bengro opened this issue Mar 7, 2017 · 1 comment
Open

Resetting js dom multiple times during mocha tests #20

bengro opened this issue Mar 7, 2017 · 1 comment

Comments

@bengro
Copy link

bengro commented Mar 7, 2017

I'm using jsdom-global in context with mocha tests, testing a react application.

The test infrastructure is built around integration tests, using enzyme's mount method. I noticed, that react is using the DOM as storage place for internal logic. This is causing side-effects between the tests which are impossible to debug. I would like to freshly setup the DOM before every test runs.

Do you have an idea, how to reset the jsdom/jsdom-global at runtime between tests? Using the mocha hooks did not work. It seems that once babel-register is activated to compile test and source, jsdom-global stops working. In other words, how can jsdom-global be used after babel-register has compiled the code?

I appreciate any input.

@gir
Copy link

gir commented May 15, 2017

I'm not totally sure of your setup, but I'm running mocha with jsdom-global and I do something like this to ensure each run is clean:

test/setup.js:

import jsdom from 'jsdom-global'

// Allows the injection for building.
jsdom()

beforeEach(() => {
  global.cleanup = jsdom()
})

afterEach(() => {
  global.cleanup()
})

mocha.opts:

--require ignore-styles
--require babel-register
--compilers jsx:babel-register
--colors
test/setup.js
test/**/*.js?

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

No branches or pull requests

2 participants