Jest upgrade to v27 was required to resolve word-wrap ReDoS vulnerability, multiple MFEs are already on v29 and some on v28, we decided to update jest to latest version which is v29, across all MFEs. Following are the details of breaking changes between each version
Introduced a few more small breaking changes to help you avoid mistakes by disallowing some things that can easily happen unintentionally:
The same done
test callback may not be called more than once,
calling done
and returning a Promise may not be combined,
a describe
block must not return anything,
and we made some TypeScript types stricter.
Modules used in the following configuration options are now transformed like the rest of your code, which may be breaking if you relied on them being loaded as-is:
testEnvironment
runner
testRunner
snapshotResolver
The supported Node versions are 12.13, 14.15, 16.10 and above.
Configuration Options:
extraGlobals: The extraGlobals
option was renamed to sandboxInjectedGlobals
:
timers: The timers
option was renamed to fakeTimers
testURL: The testURL
option is removed. Now you should use testEnvironmentOptions
to pass url
option to JSDOM environment
Babel Config: babel-jest
now passes root: config.rootDir
to Babel when resolving configuration.
expect: In versions prior to Jest 28, toHaveProperty
checked for equality instead of existence, which means that e.g. expect({}).toHaveProperty('a', undefined)
is a passing test. This has been changed in Jest 28 to fail. Additionally, if you import expect
directly, it has been changed from default export to a named export
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
jest.useFakeTimers(): An object with options now should be passed to jest.useFakeTimers()
as well
Test Environment:
Custom Environment: The constructor of test environment class now receives an object with Jest's globalConfig
and projectConfig
as its first argument. The second argument is now mandatory. In addition, test environments are now exported with the name TestEnvironment
, instead of simply exporting the class directly:
jsdom: If you are using JSDOM test environment, jest-environment-jsdom
package now must be installed separately
Test Runner: When using Jasmine test runner, jest-jasmine2
package now must be installed separately.
Transformer: process()
and processAsync()
methods of a custom transformer module cannot return a string anymore. They must always return an object.
Typescript
jest.fn(): now takes only one generic type argument
The supported Node versions are 14.15, 16.10, 18.0 and above. v29 introduces following breaking changes
Snapshot format: Jest 29 has changed the default snapshot formatting to {escapeString: false, printBasicPrototype: false}
JSDOM upgrade: jest-environment-jsdom
has upgraded jsdom
from v19 to v20. If you use jest-environment-jsdom
, the minimum TypeScript version is set to 4.5
. Notably, jsdom@20
includes support for crypto.getRandomValues()
, which means packages like uuid
and nanoid
, which doesn't work properly in Jest@28, can work without extra polyfills.
pretty-format​: ConvertAnsi
plugin is removed from pretty-format
package in favour of jest-serializer-ansi-escapes
.
jest-mock: Exports of Mocked*
utility types from jest-mock
package have changed. MaybeMockedDeep
and MaybeMocked
now are exported as Mocked
and MockedShallow
respectively; only deep mocked variants of MockedClass
, MockedFunction
and MockedObject
are exposed.
jest.mocked(): The jest.mocked()
helper method now wraps types of deep members of passed object by default. If you have used the method with true
as the second argument, remove it to avoid type errors