Promisified jsdom setup and teardown for your test runner.
yarn add -D jazzdom jsdom jsdom-global
Option 1: Setting up and tearing down for tests that need a document object
Option 2: Global setup line for test/mocha.opts
Don't do this if you plan to use the other setup option.
In your mocha tests:
- If you trust your tests to clean up after themselves, you may wish to call
require ('jazzdom/register')only once across your entire test suite, since that may result in speed improvements.
- It can be good to separate fast and slow tests. "slow" tests would require
jazzdom.create(), or other expensive tasks, and "fast" tests would not. Name them with slightly different patterns, and have two different test rules in
package.jsonto call each suite. Prefer to have more fast tests and less slow tests. Instead of making multiple slow tests, consider making one slow test and spies for the remaining tests, if that makes sense for the situation.
- Try to call
jazzdom.destroy()only when they're needed, such as with
enzyme.mount(), and omit them with
- It's almost never a good idea to put
after()blocks, or in dedicated
it()blocks if your test runner doesn't support
Additional features compared to jsdom-global
- Returns promises in separate
- Automatically routes
<script>tags into the standard node.js
- Waits for jsdom
createdevent to be fired before fulfilling or rejecting promise
- If you forgot to
destroy()the previous setup, the next
create()call will throw an error that points to the previous invocation