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
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
Jest v28 Upgrade (Complete changelog)
The supported Node versions are 12.13, 14.15, 16.10 and above.
Configuration Options:
extraGlobals: The
extraGlobals
option was renamed tosandboxInjectedGlobals
:timers: The
timers
option was renamed tofakeTimers
testURL: The
testURL
option is removed. Now you should usetestEnvironmentOptions
to passurl
option to JSDOM environmentBabel Config:
babel-jest
now passesroot: 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 importexpect
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 tofakeTimers
and 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
globalConfig
andprojectConfig
as 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-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
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-jsdom
has upgradedjsdom
from v19 to v20. If you usejest-environment-jsdom
, the minimum TypeScript version is set to4.5
. Notably,jsdom@20
includes support forcrypto.getRandomValues()
, which means packages likeuuid
andnanoid
, which doesn't work properly in Jest@28, can work without extra polyfills.pretty-format:
ConvertAnsi
plugin is removed frompretty-format
package in favour ofjest-serializer-ansi-escapes
.jest-mock: Exports of
Mocked*
utility types fromjest-mock
package have changed.MaybeMockedDeep
andMaybeMocked
now are exported asMocked
andMockedShallow
respectively; only deep mocked variants ofMockedClass
,MockedFunction
andMockedObject
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 withtrue
as the second argument, remove it to avoid type errors