Skip to content

Upgrading @jest/globals 26 to 27

Breaking26.6.2 → 27.5.1Breaking52Platform2Deprecated1New56Changed24Fixed99Other18

BreakingUpgrade verdict

52 breaking changes and 2 platform requirement changes.

  • Fake timers now use the modern implementation by default.
  • When resolving files, .json is now tried after .ts and .tsx instead of before them.
  • jsdom tests no longer have setImmediate and clearImmediate available as globals.
  • Three old Jest APIs that were deprecated for a long time are gone.
Top 5 of 55 that need code or config changes

Node.js requirement changed in 27.0.0-next.0: >= 10.14.2 → ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0.

Installs 47 packages in all (was 48).

Breaking52
Uses the modern implementation as the default for fake timers.
fakeTimersjest-configjest-runtime
Changes the default file extension order by moving json behind ts and tsx.
jest-config
Removes Node globals setImmediate and clearImmediate from jest-environment-jsdom.
setImmediateclearImmediate
Removes long-deprecated jest.addMatchers, jest.resetModuleRegistry, and jest.runTimersToTime.
jest.addMatchersjest.resetModuleRegistryjest.runTimersToTime
Removes the deprecated mapCoverage option.
mapCoverage
Removes the enabledTestsMap config in favor of filter.
enabledTestsMapfilter
Removes support for the deprecated ignorePattern option as a function.
ignorePattern
Removes the unused options argument from the Env constructor in jest-jasmine2.
Env
Removes the deprecated and unused getSourceMapInfo from Runtime.
RuntimegetSourceMapInfo
Removes the unused isCoreModule option from jest-transformer.
isCoreModulejest-transformer
Removes the recursiveBlacklist option in favor of recursiveDenylist in jest-validate.
recursiveBlacklistrecursiveDenylist
jest-config defaults to the Node testing environment instead of browser (JSDOM).
testEnvironmentjest-config
jest-config uses jest-circus as the default test runner.
jest-circustestRunnerjest-config
Adds a custom HasteMap class implementation config option.
HasteMapjest-haste-mapjest-config
Runs transforms over the environment in jest-repl and jest-runner.
Runs transforms over runner in jest-runner.
Runs transforms over testRunner in jest-runner.
testRunner
Makes prettier optional for inline snapshots, falling back to string replacement.
prettier
Runs transforms over snapshotResolver in jest-snapshot.
snapshotResolver
Stops exporting ScriptTransformer class and instead exports async function createScriptTransformer.
ScriptTransformercreateScriptTransformer
requireAndTranspileModule always returns a Promise and its third parameter is now RequireAndTranspileModuleOptions.
requireAndTranspileModuleRequireAndTranspileModuleOptionsapplyInteropRequireDefault
createTranspilingRequire now returns a function that returns a Promise.
createTranspilingRequire
Revises expect.not.objectContaining() to be the inverse of expect.objectContaining(), as documented.
expect.not.objectContaining()expect.objectContaining()
Makes toContain more strict about the received type.
toContain
matcherResult on JestAssertionError is now strings rather than functions.
matcherResultJestAssertionError
Uses only named exports in jest-diff.
jest-diff
Ignores excess words in jest-each headings.
jest-each
Drops support for runScript for test environments.
runScript
Converts jest-get-type to an ES Module.
jest-get-type
Stops injecting the global variable into the module wrapper.
global
Refactors the transform API to pass an options bag instead of multiple boolean options.
Refactors transformer API to pass an options bag rather than separate config and other options.
config
Switches jest-worker to named exports.
Converts pretty-format to ES Modules.
pretty-format
Adds an exports field to all package.json files.
exports
Migrates babel-jest to ESM.
babel-jest
Replaces the TestScheduler export with createTestScheduler.
TestSchedulercreateTestScheduler
Moves root into config and makes GlobalConfig a mandatory parameter for getConsoleOutput.
rootconfigGlobalConfiggetConsoleOutput
Migrates jest-haste-map to ESM.
jest-haste-map
Migrates jest-jasmine2 to ESM.
jest-jasmine2
Moves the jest-runtime CLI into jest-repl.
jest-runtimejest-repl
Migrates jest-resolve to ESM.
jest-resolve
Migrates jest-resolve-dependencies to ESM.
jest-resolve-dependencies
Makes node-notifier a peer dependency of jest-reporters.
node-notifierjest-reporters
Uses Maps instead of objects for all cached resources in jest-resolve and jest-runtime.
jest-resolvejest-runtimeMap
Migrates jest-runner to ESM.
jest-runner
jest-circus now fails tests when multiple done() calls are made.
done()jest-circus
jest-circus and jest-jasmine2 fail the test instead of warning when describe returns a value.
describejest-circusjest-jasmine2
Sets exit code to 1 if test logs after teardown in jest-runner.
Disallows return values other than a Promise from hooks and tests.
Promise
Disallows mixing a done callback and returning a Promise from hooks and tests.
donePromise
Migrates jest-mock to ESM.
jest-mock
Platform2
Allows node-notifier@10 as a peer dependency of @jest/reporters.
node-notifier
Drops support for non-LTS Node versions, supporting only Node LTS releases and Node 15.
Deprecated1
Marks deprecated configuration options as @deprecated in @jest/types.
@deprecated