How to disable jsdom in jest — make jest run twice as fast

Image for post
Image for post

Jest is a awesome test runner, a lot of features works great out of the box like watcher, code coverage, status screen and much more, however jest is a little bit slower than other test runners simply because it does more. It is generally not a problem when you run in watch mode. One reason jest is slower is that it ensures encapsulation between tests so they don’t leak and make other tests fail. Another reason is jsdom is attached to each test file and jsdom is a whole browser DOM emulated in javascript, you can imagine that is not a small code footprint! So if you are only making something for node.js and don’t have any tests for React.js as example, then you can with benefit disable that feature!

Do that by adding a key called “jest” in your package.json and write it like this:

"jest": {
"testEnvironment": "node"

That will make your test run about 2X faster when you do a full test suite run and that can be a benefit if you have a lot of tests!

Now however will document be undefined, so any test that depend on the DOM will be null or have a reference error.

You can read more about the settings of jest here and other cool settings like notify

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store