Skip to content

Latest commit

 

History

History
84 lines (63 loc) · 1.95 KB

UpgradingGuide.md

File metadata and controls

84 lines (63 loc) · 1.95 KB
id title
upgrading-guide
From v27 to v28

Upgrading Jest from v27 to v28? This guide aims to help refactoring your tests.

Fake Timers

Fake timers were refactored to allow passing options to the underlying @sinonjs/fake-timers.

fakeTimers

The timers configuration option was renamed to fakeTimers and now takes an object with options:

- timers: 'real'
+ fakeTimers: {
+   enableGlobally: false
+ }
- timers: 'fake'
+ fakeTimers: {
+   enableGlobally: true
+ }
- timers: 'modern'
+ fakeTimers: {
+   enableGlobally: true
+ }
- timers: 'legacy'
+ fakeTimers: {
+   enableGlobally: true,
+   legacyFakeTimers: true
+ }

jest.useFakeTimers()

An object with options now should be passed to jest.useFakeTimers() as well:

- jest.useFakeTimers('modern')
+ jest.useFakeTimers()

Or if legacy fake timers are enabled in Jest config file, but you would like to use the default fake timers backed by @sinonjs/fake-timers:

- jest.useFakeTimers('modern')
+ jest.useFakeTimers({
+   legacyFakeTimers: false
+ })
- jest.useFakeTimers('legacy')
+ jest.useFakeTimers({
+   legacyFakeTimers: true
+ })

Test Environment

If you are using JSDOM test environment, jest-environment-jsdom package now must be installed additionally:

npm install --save-dev jest-environment-jsdom

Test Runner

If you are using Jasmine test runner, jest-jasmine2 package now must be installed additionally:

npm install --save-dev jest-jasmine2