@nx/jest - Migrations
The @nx/jest plugin provides various migrations to help you migrate to newer versions of jest projects within your Nx workspace. Below is a complete reference for all available migrations.
22.3.x
Section titled “22.3.x”replace-removed-matcher-aliases-v22-3
Section titled “replace-removed-matcher-aliases-v22-3”Version: 22.3.2-beta.0
Replace removed matcher aliases in Jest v30 with their corresponding matcher
Requires
Section titled “Requires”| Name | Version |
|---|---|
jest | >=30.0.0 |
Replace Removed Matcher Aliases
Section titled “Replace Removed Matcher Aliases”Replaces removed Jest matcher aliases in test files with their corresponding matchers to align with Jest v30 changes. Read more at the Jest v30 migration notes.
Examples
Section titled “Examples”Before
Section titled “Before”describe('test', () => { it('should pass', async () => { expect(mockFn).toBeCalled(); expect(mockFn).toBeCalledTimes(1); expect(mockFn).toBeCalledWith(arg); expect(mockFn).lastCalledWith(arg); expect(mockFn).nthCalledWith(1, arg); expect(mockFn).toReturn(); expect(mockFn).toReturnTimes(1); expect(mockFn).toReturnWith(value); expect(mockFn).lastReturnedWith(value); expect(mockFn).nthReturnedWith(1, value); expect(() => someFn()).toThrowError(); expect(() => someFn()).not.toThrowError(); await expect(someAsyncFn()).rejects.toThrowError(); await expect(someAsyncFn()).resolves.not.toThrowError(); });});describe('test', () => { it('should pass', async () => { expect(mockFn).toHaveBeenCalled(); expect(mockFn).toHaveBeenCalledTimes(1); expect(mockFn).toHaveBeenCalledWith(arg); expect(mockFn).toHaveBeenLastCalledWith(arg); expect(mockFn).toHaveBeenNthCalledWith(1, arg); expect(mockFn).toHaveReturned(); expect(mockFn).toHaveReturnedTimes(1); expect(mockFn).toHaveReturnedWith(value); expect(mockFn).toHaveLastReturnedWith(value); expect(mockFn).toHaveNthReturnedWith(1, value); expect(() => someFn()).toThrow(); expect(() => someFn()).not.toThrow(); await expect(someAsyncFn()).rejects.toThrow(); await expect(someAsyncFn()).resolves.not.toThrow(); });});22.3.0-package-updates
Section titled “22.3.0-package-updates”Version: 22.3.0-beta.3
Packages
Section titled “Packages”The following packages will be updated:
| Name | Version | Always add to package.json |
|---|---|---|
jest | ^30.0.0 | Updated only |
@types/jest | ^30.0.0 | Updated only |
expect | ^30.0.0 | Updated only |
@jest/globals | ^30.0.0 | Updated only |
jest-jasmine2 | ^30.0.0 | Updated only |
jest-environment-jsdom | ^30.0.0 | Updated only |
jest-util | ^30.0.0 | Updated only |
babel-jest | ^30.0.0 | Updated only |
@swc/jest | ~0.2.38 | Updated only |
22.3.0-jest-preset-angular-package-updates
Section titled “22.3.0-jest-preset-angular-package-updates”Version: 22.3.0-beta.3
Packages
Section titled “Packages”The following packages will be updated:
| Name | Version | Always add to package.json |
|---|---|---|
jest-preset-angular | ~16.0.0 | Updated only |
22.2.x
Section titled “22.2.x”convert-jest-config-to-cjs
Section titled “convert-jest-config-to-cjs”Version: 22.2.0-beta.2
Convert jest.config.ts files from ESM to CJS syntax (export default -> module.exports, import -> require) for projects using CommonJS resolution to ensure correct loading under Node.js type-stripping.
Convert Jest Config to CJS
Section titled “Convert Jest Config to CJS”Converts jest.config.ts files to jest.config.cts. This is needed because Node.js type-stripping in newer versions (22+, 24+) can cause issues with ESM syntax in .ts files when the project is configured for CommonJS.
This migration only runs if @nx/jest/plugin is registered in nx.json.
Examples
Section titled “Examples”Before
Section titled “Before”import { foo } from 'bar';import baz from 'qux';
export default { displayName: 'myapp', preset: foo, transform: baz,};const { foo } = require('bar');const baz = require('qux').default ?? require('qux');
module.exports = { displayName: 'myapp', preset: foo, transform: baz,};21.3.x
Section titled “21.3.x”rename-test-path-pattern
Section titled “rename-test-path-pattern”Version: 21.3.0-beta.3
Rename the CLI option testPathPattern to testPathPatterns.
Rename testPathPattern to testPathPatterns
Section titled “Rename testPathPattern to testPathPatterns”Renames the testPathPattern option to testPathPatterns in the @nx/jest:jest executor configuration to align with Jest v30 CLI changes. Read more at the Jest v30 migration notes.
Examples
Section titled “Examples”Rename the option in project configuration:
Before
Section titled “Before”{ "targets": { "test": { "executor": "@nx/jest:jest", "options": { "jestConfig": "apps/myapp/jest.config.ts", "testPathPattern": "some-regex" } } }}{ "targets": { "test": { "executor": "@nx/jest:jest", "options": { "jestConfig": "apps/myapp/jest.config.ts", "testPathPatterns": "some-regex" } } }}Rename the option in project configuration with configurations:
Before
Section titled “Before”{ "targets": { "test": { "executor": "@nx/jest:jest", "options": { "jestConfig": "apps/myapp/jest.config.ts", "testPathPattern": "some-regex" }, "configurations": { "development": { "testPathPattern": "regex-dev" }, "production": { "testPathPattern": "regex-prod" } } } }}{ "targets": { "test": { "executor": "@nx/jest:jest", "options": { "jestConfig": "apps/myapp/jest.config.ts", "testPathPatterns": "some-regex" }, "configurations": { "development": { "testPathPatterns": "regex-dev" }, "production": { "testPathPatterns": "regex-prod" } } } }}Rename the option in a target default using the @nx/jest:jest executor:
Before
Section titled “Before”{ "targetDefaults": { "test": { "executor": "@nx/jest:jest", "options": { "jestConfig": "{projectRoot}/jest.config.ts", "testPathPattern": "some-regex" } } }}{ "targetDefaults": { "test": { "executor": "@nx/jest:jest", "options": { "jestConfig": "{projectRoot}/jest.config.ts", "testPathPatterns": "some-regex" } } }}Rename the option in a target default using the @nx/jest:jest executor as the key:
Before
Section titled “Before”{ "targetDefaults": { "@nx/jest:jest": { "options": { "jestConfig": "{projectRoot}/jest.config.ts", "testPathPattern": "some-regex" } } }}{ "targetDefaults": { "@nx/jest:jest": { "options": { "jestConfig": "{projectRoot}/jest.config.ts", "testPathPatterns": "some-regex" } } }}replace-removed-matcher-aliases
Section titled “replace-removed-matcher-aliases”Version: 21.3.0-beta.3
Replace removed matcher aliases in Jest v30 with their corresponding matcher
Requires
Section titled “Requires”| Name | Version |
|---|---|
jest | >=30.0.0 |
Replace Removed Matcher Aliases
Section titled “Replace Removed Matcher Aliases”Replaces removed Jest matcher aliases in test files with their corresponding matchers to align with Jest v30 changes. Read more at the Jest v30 migration notes.
Examples
Section titled “Examples”Before
Section titled “Before”describe('test', () => { it('should pass', async () => { expect(mockFn).toBeCalled(); expect(mockFn).toBeCalledTimes(1); expect(mockFn).toBeCalledWith(arg); expect(mockFn).lastCalledWith(arg); expect(mockFn).nthCalledWith(1, arg); expect(mockFn).toReturn(); expect(mockFn).toReturnTimes(1); expect(mockFn).toReturnWith(value); expect(mockFn).lastReturnedWith(value); expect(mockFn).nthReturnedWith(1, value); expect(() => someFn()).toThrowError(); expect(() => someFn()).not.toThrowError(); await expect(someAsyncFn()).rejects.toThrowError(); await expect(someAsyncFn()).resolves.not.toThrowError(); });});describe('test', () => { it('should pass', async () => { expect(mockFn).toHaveBeenCalled(); expect(mockFn).toHaveBeenCalledTimes(1); expect(mockFn).toHaveBeenCalledWith(arg); expect(mockFn).toHaveBeenLastCalledWith(arg); expect(mockFn).toHaveBeenNthCalledWith(1, arg); expect(mockFn).toHaveReturned(); expect(mockFn).toHaveReturnedTimes(1); expect(mockFn).toHaveReturnedWith(value); expect(mockFn).toHaveLastReturnedWith(value); expect(mockFn).toHaveNthReturnedWith(1, value); expect(() => someFn()).toThrow(); expect(() => someFn()).not.toThrow(); await expect(someAsyncFn()).rejects.toThrow(); await expect(someAsyncFn()).resolves.not.toThrow(); });});21.3.0-package-updates
Section titled “21.3.0-package-updates”Version: 21.3.0-beta.3
Packages
Section titled “Packages”The following packages will be updated:
| Name | Version | Always add to package.json |
|---|---|---|
jest | ~30.0.0 | Updated only |
@types/jest | ~30.0.0 | Updated only |
expect | ~30.0.0 | Updated only |
@jest/globals | ~30.0.0 | Updated only |
jest-jasmine2 | ~30.0.0 | Updated only |
jest-environment-jsdom | ~30.0.0 | Updated only |
babel-jest | ~30.0.0 | Updated only |
@swc/jest | ~0.2.38 | Updated only |
21.3.3-package-updates
Section titled “21.3.3-package-updates”Version: 21.3.3-beta.0
Packages
Section titled “Packages”The following packages will be updated:
| Name | Version | Always add to package.json |
|---|---|---|
ts-jest | ~29.4.0 | Updated only |
21.3.3-jest-util-package-updates
Section titled “21.3.3-jest-util-package-updates”Version: 21.3.3-beta.3
Packages
Section titled “Packages”The following packages will be updated:
| Name | Version | Always add to package.json |
|---|---|---|
jest-util | ~30.0.0 | Updated only |
21.0.x
Section titled “21.0.x”replace-getJestProjects-with-getJestProjectsAsync-v21
Section titled “replace-getJestProjects-with-getJestProjectsAsync-v21”Version: 21.0.0-beta.9
Replace usage of getJestProjects with getJestProjectsAsync.
Replace Usage of getJestProjects with getJestProjectsAsync
Section titled “Replace Usage of getJestProjects with getJestProjectsAsync”Replaces the usage of the removed getJestProjects function with the getJestProjectsAsync function.
Sample Code Changes
Section titled “Sample Code Changes”Before
Section titled “Before”import { getJestProjects } from '@nx/jest';
export default { projects: getJestProjects(),};import { getJestProjectsAsync } from '@nx/jest';
export default async () => ({ projects: await getJestProjectsAsync(),});remove-tsconfig-option-from-jest-executor
Section titled “remove-tsconfig-option-from-jest-executor”Version: 21.0.0-beta.10
Remove the previously deprecated and unused tsConfig option from the @nx/jest:jest executor.
Remove tsConfig Option from Jest Executor
Section titled “Remove tsConfig Option from Jest Executor”Removes the previously deprecated and unused tsConfig option from the @nx/jest:jest executor configuration in all projects.
Examples
Section titled “Examples”Remove the option from the project configuration:
Before
Section titled “Before”{ "targets": { "test": { "executor": "@nx/jest:jest", "options": { "jestConfig": "apps/myapp/jest.config.ts", "tsConfig": "apps/myapp/tsconfig.spec.json" } } }}{ "targets": { "test": { "executor": "@nx/jest:jest", "options": { "jestConfig": "apps/myapp/jest.config.ts" } } }}Remove the option from a target default using the @nx/jest:jest executor:
Before
Section titled “Before”{ "targetDefaults": { "test": { "executor": "@nx/jest:jest", "options": { "jestConfig": "{projectRoot}/jest.config.ts", "tsConfig": "{projectRoot}/tsconfig.spec.json" } } }}{ "targetDefaults": { "test": { "executor": "@nx/jest:jest", "options": { "jestConfig": "{projectRoot}/jest.config.ts" } } }}Remove the option from a target default using the @nx/jest:jest executor as the key:
Before
Section titled “Before”{ "targetDefaults": { "@nx/jest:jest": { "options": { "jestConfig": "{projectRoot}/jest.config.ts", "tsConfig": "{projectRoot}/tsconfig.spec.json" } } }}{ "targetDefaults": { "@nx/jest:jest": { "options": { "jestConfig": "{projectRoot}/jest.config.ts" } } }}20.0.x
Section titled “20.0.x”replace-getJestProjects-with-getJestProjectsAsync
Section titled “replace-getJestProjects-with-getJestProjectsAsync”Version: 20.0.0-beta.5
Replace usage of getJestProjects with getJestProjectsAsync.
Replace Usage of getJestProjects with getJestProjectsAsync
Section titled “Replace Usage of getJestProjects with getJestProjectsAsync”Replaces the usage of the deprecated getJestProjects function with the getJestProjectsAsync function.
Sample Code Changes
Section titled “Sample Code Changes”Before
Section titled “Before”import { getJestProjects } from '@nx/jest';
export default { projects: getJestProjects(),};import { getJestProjectsAsync } from '@nx/jest';
export default async () => ({ projects: await getJestProjectsAsync(),});