Skip to content
🚀 We’re live on Product Hunt Vote or leave a comment today!

@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.

Version: 23.0.0-beta.10

Update the Jest snapshot guide link in .snap files from the legacy https://goo.gl/fbAQLP URL to https://jestjs.io/docs/snapshot-testing, which Jest v30 now requires.

NameVersion
jest>=30.0.0

Updates the snapshot guide link at the top of every .snap file from the legacy https://goo.gl/fbAQLP to https://jestjs.io/docs/snapshot-testing. Jest v30 errors out at test setup time if it sees the old link, so existing snapshot files need to be rewritten before tests can run. Read more at the Jest v30 migration notes.

apps/myapp/src/__snapshots__/example.spec.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders correctly 1`] = `"hello"`;
apps/myapp/src/__snapshots__/example.spec.ts.snap
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`renders correctly 1`] = `"hello"`;

Version: 23.0.0-beta.16

Rewrites @nx/jest/src/* subpath imports now that the ./src/* subpath is no longer exposed by @nx/jest’s exports map. Named imports/exports of public symbols are routed to @nx/jest and the rest to the new @nx/jest/internal entry; require, dynamic import and jest.mock calls reference the whole module and are routed to @nx/jest/internal.

Version: 23.0.0-beta.16

Replaces the removed jestProjectGenerator export from @nx/jest with its replacement configurationGenerator.

Version: 23.0.0-beta.22

Migrate the deprecated setupFile option of the @nx/jest:jest executor: push the file path into setupFilesAfterEnv in the project’s Jest config and remove the option from project.json and nx.json target defaults.

Migrate setupFile Option to setupFilesAfterEnv

Section titled “Migrate setupFile Option to setupFilesAfterEnv”

Migrates the previously deprecated setupFile option of the @nx/jest:jest executor. The setup file path is appended to the setupFilesAfterEnv array in the project’s Jest configuration (using <rootDir>/... form), and the deprecated option is removed from project.json and nx.json target defaults.

If the Jest configuration cannot be parsed automatically (e.g. it exports a factory function or assigns setupFilesAfterEnv to a non-array value), the deprecated option is still removed and a warning is logged listing the affected projects so the setup file path can be moved manually.

Push the setup file into the project’s Jest configuration and remove the option from project.json:

apps/myapp/project.json
{
"targets": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/myapp/jest.config.ts",
"setupFile": "apps/myapp/src/test-setup.ts"
}
}
}
}
apps/myapp/jest.config.ts
export default {
displayName: 'myapp',
};
apps/myapp/project.json
{
"targets": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/myapp/jest.config.ts"
}
}
}
}
apps/myapp/jest.config.ts
export default {
displayName: 'myapp',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
};

Append to an existing setupFilesAfterEnv array:

apps/myapp/project.json
{
"targets": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/myapp/jest.config.ts",
"setupFile": "apps/myapp/src/test-setup.ts"
}
}
}
}
apps/myapp/jest.config.ts
export default {
displayName: 'myapp',
setupFilesAfterEnv: ['<rootDir>/src/existing-setup.ts'],
};
apps/myapp/project.json
{
"targets": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/myapp/jest.config.ts"
}
}
}
}
apps/myapp/jest.config.ts
export default {
displayName: 'myapp',
setupFilesAfterEnv: [
'<rootDir>/src/existing-setup.ts',
'<rootDir>/src/test-setup.ts',
],
};

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

nx.json
{
"targetDefaults": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"setupFile": "{projectRoot}/src/test-setup.ts"
}
}
}
}
nx.json
{
"targetDefaults": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "{projectRoot}/jest.config.ts"
}
}
}
}

Per-project paths don’t make sense as workspace defaults, so the option is removed without rewriting individual project Jest configs. A warning is logged so the setup file path can be added to each project’s Jest config manually if needed.

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

nx.json
{
"targetDefaults": {
"@nx/jest:jest": {
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"setupFile": "{projectRoot}/src/test-setup.ts"
}
}
}
}
nx.json
{
"targetDefaults": {
"@nx/jest:jest": {
"options": {
"jestConfig": "{projectRoot}/jest.config.ts"
}
}
}
}

migrate-jest-configuration-skip-setup-file

Section titled “migrate-jest-configuration-skip-setup-file”

Version: 23.0.0-beta.22

Migrate the deprecated skipSetupFile option of the @nx/jest:configuration generator stored as a default in nx.json or per-project project.json to setupFile: 'none' (when true) or remove it (when false).

Migrate skipSetupFile Generator Default to setupFile

Section titled “Migrate skipSetupFile Generator Default to setupFile”

Migrates the previously deprecated skipSetupFile option of the @nx/jest:configuration generator. When set as a default in nx.json generators or per-project project.json generators, it is rewritten as follows:

  • skipSetupFile: true becomes setupFile: 'none' (preserving the original behavior of skipping the setup file). Existing setupFile values are left untouched.
  • skipSetupFile: false is dropped (it was a no-op).

Both flat (@nx/jest:configuration) and nested (@nx/jestconfiguration) forms are handled.

Rewrite a nx.json generator default:

nx.json
{
"generators": {
"@nx/jest:configuration": {
"skipSetupFile": true
}
}
}
nx.json
{
"generators": {
"@nx/jest:configuration": {
"setupFile": "none"
}
}
}

Drop the option when set to false:

nx.json
{
"generators": {
"@nx/jest:configuration": {
"skipSetupFile": false,
"testEnvironment": "jsdom"
}
}
}
nx.json
{
"generators": {
"@nx/jest:configuration": {
"testEnvironment": "jsdom"
}
}
}

Rewrite a per-project generator default:

apps/myapp/project.json
{
"generators": {
"@nx/jest:configuration": {
"skipSetupFile": true
}
}
}
apps/myapp/project.json
{
"generators": {
"@nx/jest:configuration": {
"setupFile": "none"
}
}
}

The nested form (@nx/jestconfiguration) is handled the same way.

update-23-0-0-migrate-create-nodes-v2-import

Section titled “update-23-0-0-migrate-create-nodes-v2-import”

Version: 23.0.0-beta.24

Rename imports of createNodesV2 from @nx/jest/plugin to the canonical createNodes export.

Rename createNodesV2 imports to createNodes

Section titled “Rename createNodesV2 imports to createNodes”

@nx/jest renamed its primary inferred-plugin export from createNodesV2 to createNodes. The createNodesV2 name is preserved as a deprecated alias for now, but new code should use createNodes.

This migration scans every .ts, .tsx, .cts, and .mts file in your workspace and rewrites named imports and re-exports of createNodesV2 from @nx/jest/plugin to createNodes.

import { createNodesV2 } from '@nx/jest/plugin';
import { createNodes } from '@nx/jest/plugin';

Aliases are preserved (createNodesV2 as cn becomes createNodes as cn), and if a file already imports both names ({ createNodes, createNodesV2 }) the redundant binding is dropped.

Only static import/export named bindings from @nx/jest/plugin are rewritten. Namespace imports, dynamic import(...), require(...) destructuring, and property access such as plugin.createNodesV2 are left untouched — they keep working through the createNodesV2 runtime alias. Update those by hand if you want to drop the deprecated name everywhere.

23.0.0-pin-jest-30-3-for-rn-compat-package-updates

Section titled “23.0.0-pin-jest-30-3-for-rn-compat-package-updates”

Version: 23.0.0-beta.9

The following packages will be updated:

NameVersionAlways add to package.json
jest~30.3.0Updated only
babel-jest~30.3.0Updated only
@types/jest~30.0.0Updated only

Version: 22.3.2-beta.0

Replace removed matcher aliases in Jest v30 with their corresponding matcher

NameVersion
jest>=30.0.0

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.

apps/myapp/src/app.spec.ts
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();
});
});
apps/myapp/src/app.spec.ts
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();
});
});

Version: 22.3.0-beta.3

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
jest-util^30.0.0Updated only
babel-jest^30.0.0Updated only
@swc/jest~0.2.38Updated 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

The following packages will be updated:

NameVersionAlways add to package.json
jest-preset-angular~16.0.0Updated only

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.

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.

jest.config.ts
import { foo } from 'bar';
import baz from 'qux';
export default {
displayName: 'myapp',
preset: foo,
transform: baz,
};
jest.config.cts
const { foo } = require('bar');
const baz = require('qux').default ?? require('qux');
module.exports = {
displayName: 'myapp',
preset: foo,
transform: baz,
};

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.

Rename the option in project configuration:

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

Rename the option in project configuration with configurations:

apps/myapp/project.json
{
"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" }
}
}
}
}
apps/myapp/project.json
{
"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:

nx.json
{
"targetDefaults": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"testPathPattern": "some-regex"
}
}
}
}
nx.json
{
"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:

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

Version: 21.3.0-beta.3

Replace removed matcher aliases in Jest v30 with their corresponding matcher

NameVersion
jest>=30.0.0

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.

apps/myapp/src/app.spec.ts
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();
});
});
apps/myapp/src/app.spec.ts
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();
});
});

Version: 21.3.0-beta.3

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

Version: 21.3.3-beta.0

The following packages will be updated:

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

Version: 21.3.3-beta.3

The following packages will be updated:

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

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.

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

Version: 21.0.0-beta.10

Remove the previously deprecated and unused tsConfig option from the @nx/jest:jest executor.

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

Remove the option from the project configuration:

apps/myapp/project.json
{
"targets": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/myapp/jest.config.ts",
"tsConfig": "apps/myapp/tsconfig.spec.json"
}
}
}
}
apps/myapp/project.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:

nx.json
{
"targetDefaults": {
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"tsConfig": "{projectRoot}/tsconfig.spec.json"
}
}
}
}
nx.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:

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