Jest 27 Has New Default
Default test environment from “jsdom” to “node”.
Modern fake timers implementation will now be the default.
The big news here is that Jest is changing the default test environment from “jsdom” to “node”.
- The most developers will see a big performance boost because they’ll no longer be unknowingly using an expensive DOM environment that they (usually) don’t need.
- Running tests in a JSDOM environment incurs a significant performance overhead. Because this was the default behavior of Jest unless otherwise configured up until now, users who are writing Node apps, for example, may not even know they are given an expensive DOM environment that they do not even need.
- For this reason, they changed the default test environment from “jsdom” to “node”. If you are affected by this change because you use DOM APIs and do not have the test environment explicitly configured, you should be receiving an error when e.g. document is accessed, and you can configure “testEnvironment”: “jsdom” or use per-file environment configuration to resolve this.
This modern fake timers implementation will now be the default (it was previously opt-in)
- Introduced an opt-in “modern” implementation of Fake Timers in Jest 26 accessed transparently through the same API, but with much more comprehensive mocking, such as for Date and queueMicrotask.
- You can get back the old implementation using jest.useFakeTimers(“legacy”) or, if you are enabling fake timers globally via configuration, “timers”: “legacy”.
Other new stuff:
- You can now interactively step through failed tests one at a time
- You can now do inline snapshots without having to use Prettier as a mandatory pre-requisite (one of Jest’s most-requested features)
Initialization per test file is almost 70% faster than it was in Jest 26 👏