id | title |
---|---|
upgrading-guide |
From v27 to v28 |
Upgrading Jest from v27 to v28? This guide aims to help refactoring your tests.
Fake timers were refactored to allow passing options to the underlying @sinonjs/fake-timers
.
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
+ }
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
+ })
If you are using JSDOM test environment, jest-environment-jsdom
package now must be installed additionally:
npm install --save-dev jest-environment-jsdom
If you are using Jasmine test runner, jest-jasmine2
package now must be installed additionally:
npm install --save-dev jest-jasmine2