Jest upgrade from v26 to v29
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
Jest v27 Upgrade (Complete changelog)
Introduced a few more small breaking changes to help you avoid mistakes by disallowing some things that can easily happen unintentionally:
The same
donetest callback may not be called more than once,calling
doneand returning a Promise may not be combined,a
describeblock 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:
testEnvironmentrunnertestRunnersnapshotResolver
Jest v28 Upgrade (Complete changelog)
The supported Node versions are 12.13, 14.15, 16.10 and above.
Configuration Options:
extraGlobals: The
extraGlobalsoption was renamed tosandboxInjectedGlobals:timers: The
timersoption was renamed tofakeTimerstestURL: The
testURLoption is removed. Now you should usetestEnvironmentOptionsto passurloption to JSDOM environmentBabel Config:
babel-jestnow passesroot: config.rootDirto Babel when resolving configuration.expect: In versions prior to Jest 28,
toHavePropertychecked 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 importexpectdirectly, 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
timersconfiguration option was renamed tofakeTimersand now takes an object with optionsjest.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
globalConfigandprojectConfigas its first argument. The second argument is now mandatory. In addition, test environments are now exported with the nameTestEnvironment, instead of simply exporting the class directly:jsdom: If you are using JSDOM test environment,
jest-environment-jsdompackage 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
Jest v29 Upgrade (Complete changelog)
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-jsdomhas upgradedjsdomfrom v19 to v20. If you usejest-environment-jsdom, the minimum TypeScript version is set to4.5. Notably,jsdom@20includes support forcrypto.getRandomValues(), which means packages likeuuidandnanoid, which doesn't work properly in Jest@28, can work without extra polyfills.pretty-format:
ConvertAnsiplugin is removed frompretty-formatpackage in favour ofjest-serializer-ansi-escapes.jest-mock: Exports of
Mocked*utility types fromjest-mockpackage have changed.MaybeMockedDeepandMaybeMockednow are exported asMockedandMockedShallowrespectively; only deep mocked variants ofMockedClass,MockedFunctionandMockedObjectare 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 withtrueas the second argument, remove it to avoid type errors