Skip to content

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.

21.3.x

rename-test-path-pattern

Version: 21.3.0-beta.3

Rename the CLI option testPathPattern to testPathPatterns.

Requires

NameVersion
jest>=30.0.0

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

Rename the option in project configuration:

{% tabs %} {% tab label=“Before” %}

{
"targets": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/myapp/jest.config.ts",
"testPathPattern": "some-regex"
}
}
}
}

{% /tab %}

{% tab label=“After” %}

{
"targets": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/myapp/jest.config.ts",
"testPathPatterns": "some-regex"
}
}
}
}

{% /tab %} {% /tabs %}

Rename the option in project configuration with configurations:

{% tabs %} {% tab label=“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" }
}
}
}
}

{% /tab %}

{% tab label=“After” %}

{
"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" }
}
}
}
}

{% /tab %} {% /tabs %}

Rename the option in a target default using the @nx/jest:jest executor:

{% tabs %} {% tab label=“Before” %}

{
"targetDefaults": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"testPathPattern": "some-regex"
}
}
}
}

{% /tab %}

{% tab label=“After” %}

{
"targetDefaults": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"testPathPatterns": "some-regex"
}
}
}
}

{% /tab %} {% /tabs %}

Rename the option in a target default using the @nx/jest:jest executor as the key:

{% tabs %} {% tab label=“Before” %}

{
"targetDefaults": {
"@nx/jest:jest": {
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"testPathPattern": "some-regex"
}
}
}
}

{% /tab %}

{% tab label=“After” %}

{
"targetDefaults": {
"@nx/jest:jest": {
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"testPathPatterns": "some-regex"
}
}
}
}

{% /tab %} {% /tabs %}

replace-removed-matcher-aliases

Version: 21.3.0-beta.3

Replace removed matcher aliases in Jest v30 with their corresponding matcher

Requires

NameVersion
jest>=30.0.0

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

{% tabs %} {% tab label=“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();
});
});

{% /tab %}

{% tab label=“After” %}

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();
});
});

{% /tab %} {% /tabs %}

21.3.0-package-updates

Version: 21.3.0-beta.3

Packages

The following packages will be updated:

NameVersionAlways add to package.json
jest~30.0.0Updated only
@types/jest~30.0.0Updated only
expect~30.0.0Updated only
@jest/globals~30.0.0Updated only
jest-jasmine2~30.0.0Updated only
jest-environment-jsdom~30.0.0Updated only
babel-jest~30.0.0Updated only
@swc/jest~0.2.38Updated only

21.3.3-package-updates

Version: 21.3.3-beta.0

Packages

The following packages will be updated:

NameVersionAlways add to package.json
ts-jest~29.4.0Updated only

21.3.3-jest-util-package-updates

Version: 21.3.3-beta.3

Packages

The following packages will be updated:

NameVersionAlways add to package.json
jest-util~30.0.0Updated only

21.0.x

replace-getJestProjects-with-getJestProjectsAsync-v21

Version: 21.0.0-beta.9

Replace usage of getJestProjects with getJestProjectsAsync.

Replace Usage of getJestProjects with getJestProjectsAsync

Replaces the usage of the removed getJestProjects function with the getJestProjectsAsync function.

Sample Code Changes

{% tabs %} {% tab label=“Before” %}

import { getJestProjects } from '@nx/jest';
export default {
projects: getJestProjects(),
};

{% /tab %} {% tab label=“After” %}

import { getJestProjectsAsync } from '@nx/jest';
export default async () => ({
projects: await getJestProjectsAsync(),
});

{% /tab %} {% /tabs %}

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

Removes the previously deprecated and unused tsConfig option from the @nx/jest:jest executor configuration in all projects.

Examples

Remove the option from the project configuration:

{% tabs %} {% tab label=“Before” %}

{
"targets": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/myapp/jest.config.ts",
"tsConfig": "apps/myapp/tsconfig.spec.json"
}
}
}
}

{% /tab %}

{% tab label=“After” %}

{
"targets": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/myapp/jest.config.ts"
}
}
}
}

{% /tab %} {% /tabs %}

Remove the option from a target default using the @nx/jest:jest executor:

{% tabs %} {% tab label=“Before” %}

{
"targetDefaults": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"tsConfig": "{projectRoot}/tsconfig.spec.json"
}
}
}
}

{% /tab %}

{% tab label=“After” %}

{
"targetDefaults": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "{projectRoot}/jest.config.ts"
}
}
}
}

{% /tab %} {% /tabs %}

Remove the option from a target default using the @nx/jest:jest executor as the key:

{% tabs %} {% tab label=“Before” %}

{
"targetDefaults": {
"@nx/jest:jest": {
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"tsConfig": "{projectRoot}/tsconfig.spec.json"
}
}
}
}

{% /tab %}

{% tab label=“After” %}

{
"targetDefaults": {
"@nx/jest:jest": {
"options": {
"jestConfig": "{projectRoot}/jest.config.ts"
}
}
}
}

{% /tab %} {% /tabs %}

20.0.x

replace-getJestProjects-with-getJestProjectsAsync

Version: 20.0.0-beta.5

Replace usage of getJestProjects with getJestProjectsAsync.

Replace Usage of getJestProjects with getJestProjectsAsync

Replaces the usage of the deprecated getJestProjects function with the getJestProjectsAsync function.

Sample Code Changes

{% tabs %} {% tab label=“Before” %}

import { getJestProjects } from '@nx/jest';
export default {
projects: getJestProjects(),
};

{% /tab %} {% tab label=“After” %}

import { getJestProjectsAsync } from '@nx/jest';
export default async () => ({
projects: await getJestProjectsAsync(),
});

{% /tab %} {% /tabs %}

19.6.x

19.6.0-package-updates

Version: 19.6.0-beta.1

Packages

The following packages will be updated:

NameVersionAlways add to package.json
jest~29.7.0Updated only
@types/jest~29.5.12Updated only
expect~29.7.0Updated only
@jest/globals~29.7.0Updated only
jest-jasmine2~29.7.0Updated only
jest-environment-jsdom~29.7.0Updated only
babel-jest~29.7.0Updated only

19.2.x

19.2.0-package-updates

Version: 19.2.0-beta.0

Packages

The following packages will be updated:

NameVersionAlways add to package.json
@swc/jest~0.2.36Updated only