From v29 to v30
Upgrading Jest from v29 to v30? Ce guide a pour but de vous aider à refactoriser votre configuration et vos tests.
See changelog for the full list of changes.
Mettre à jour depuis une ancienne version ? You can see the upgrade guide from v28 to v29 here.
Compatibilité
- Jest 30 drops support for Node 14, 16, 19, and 21. The minimum supported Node versions are now 18.x. Ensure your environment is using a compatible Node release before upgrading.
- The minimum TypeScript version is now 5.4. Update TypeScript, if you are using type definitions of Jest (or any of its packages).
- The
jest-environment-jsdom
package now uses JSDOM v26. This update may introduce behavior changes in the DOM environment. If you encounter differences in DOM behavior or new warnings, refer to the JSDOM release notes for v21–26.
Jest Expect & Matchers
Removal of Alias Matcher Functions
All alias matcher names have been removed in favor of their primary names. If you have been using older, deprecated matcher names, you will need to update your tests:
- Removed aliases and their replacements:
expect(fn).toBeCalled()
→expect(fn).toHaveBeenCalled()
expect(fn).toBeCalledTimes(n)
→expect(fn).toHaveBeenCalledTimes(n)
expect(fn).toBeCalledWith(arg)
→expect(fn).toHaveBeenCalledWith(arg)
expect(fn).lastCalledWith(arg)
→expect(fn).toHaveBeenLastCalledWith(arg)
expect(fn).nthCalledWith(n, arg)
→expect(fn).toHaveBeenNthCalledWith(n, arg)
expect(fn).toReturn()
→expect(fn).toHaveReturned()
expect(fn).toReturnTimes(n)
→expect(fn).toHaveReturnedTimes(n)
expect(fn).toReturnWith(val)
→expect(fn).toHaveReturnedWith(val)
expect(fn).lastReturnedWith(val)
→expect(fn).toHaveLastReturnedWith(val)
expect(fn).nthReturnedWith(n, val)
→expect(fn).toHaveNthReturnedWith(n, val)
expect(func).toThrowError(message)
→expect(func).toThrow(message)
These alias methods were deprecated since Jest 26, and in Jest 30 they are fully removed. Perform a global search-and-replace in your codebase to update to the canonical matcher names. The functionality is identical — only the method names have changed. (If you use ESLint with eslint-plugin-jest
, the no-alias-methods
rule can help automate this replacement.)
Non-enumerable properties
Non-enumerable object properties are now excluded from object matchers by default. This could affect expect.objectContaining
or equality checks.
Improved Type Inference for CalledWith
TypeScript users: The types for the CalledWith
family of matchers (e.g. toHaveBeenCalledWith
) have been improved to infer function parameter types. In most cases this will catch type mismatches more accurately. This is a compile-time breaking change.
If you were asserting calls with arguments that don’t match the actual function’s parameter types, TypeScript may now error on those tests. For example, if a function is typed to accept a number and you wrote expect(fn).toHaveBeenCalledWith("string")
, TypeScript 5 + Jest 30’s types will flag this. The runtime behavior of the matcher is unchanged.
To fix new TypeScript errors, ensure your test arguments align with the function’s expected types (or use type casts if you intentionally call with different types).
This change doesn’t impact runtime, but it can surface new type errors in your tests that were previously unnoticed, making your tests more type-safe.