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

Kevin Simper
2 min readFeb 15, 2018

--

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 https://facebook.github.io/jest/docs/en/configuration.html#browser-boolean

--

--

Kevin Simper
Kevin Simper

Written by Kevin Simper

I really like building stuff with React.js and Docker and also Meetups ❤

Responses (1)