@nx/jest

Package reference

Here is a list of all the executors, generators and migrations available from this package.

Executors

  • jest

    Run Jest unit tests.

Generators

  • initInternal

    Initialize the @nx/jest plugin.

  • configurationInternal

    Add Jest configuration to a project.

  • convert-to-inferred

    Convert existing Jest project(s) using @nx/jest:jest executor to use @nx/jest/plugin.

Migrations

  • 21.3.x

  • rename-test-path-pattern

    Rename the CLI option `testPathPattern` to `testPathPatterns`.

    Version: 21.3.0-beta.3

    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:

    apps/myapp/project.json
    1{ 2 "targets": { 3 "test": { 4 "executor": "@nx/jest:jest", 5 "options": { 6 "jestConfig": "apps/myapp/jest.config.ts", 7 "testPathPattern": "some-regex" 8 } 9 } 10 } 11} 12

    Rename the option in project configuration with configurations:

    apps/myapp/project.json
    1{ 2 "targets": { 3 "test": { 4 "executor": "@nx/jest:jest", 5 "options": { 6 "jestConfig": "apps/myapp/jest.config.ts", 7 "testPathPattern": "some-regex" 8 }, 9 "configurations": { 10 "development": { "testPathPattern": "regex-dev" }, 11 "production": { "testPathPattern": "regex-prod" } 12 } 13 } 14 } 15} 16

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

    nx.json
    1{ 2 "targetDefaults": { 3 "test": { 4 "executor": "@nx/jest:jest", 5 "options": { 6 "jestConfig": "{projectRoot}/jest.config.ts", 7 "testPathPattern": "some-regex" 8 } 9 } 10 } 11} 12

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

    nx.json
    1{ 2 "targetDefaults": { 3 "@nx/jest:jest": { 4 "options": { 5 "jestConfig": "{projectRoot}/jest.config.ts", 6 "testPathPattern": "some-regex" 7 } 8 } 9 } 10} 11

    replace-removed-matcher-aliases

    Replace removed matcher aliases in Jest v30 with their corresponding matcher

    Version: 21.3.0-beta.3

    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

    apps/myapp/src/app.spec.ts
    1describe('test', () => { 2 it('should pass', async () => { 3 expect(mockFn).toBeCalled(); 4 expect(mockFn).toBeCalledTimes(1); 5 expect(mockFn).toBeCalledWith(arg); 6 expect(mockFn).lastCalledWith(arg); 7 expect(mockFn).nthCalledWith(1, arg); 8 expect(mockFn).toReturn(); 9 expect(mockFn).toReturnTimes(1); 10 expect(mockFn).toReturnWith(value); 11 expect(mockFn).lastReturnedWith(value); 12 expect(mockFn).nthReturnedWith(1, value); 13 expect(() => someFn()).toThrowError(); 14 expect(() => someFn()).not.toThrowError(); 15 await expect(someAsyncFn()).rejects.toThrowError(); 16 await expect(someAsyncFn()).resolves.not.toThrowError(); 17 }); 18}); 19

    21.3.0-package-updates

    Version: 21.3.0-beta.3

    Packages

    NameVersionAlways Add to package.json
    jest~30.0.0Update only
    @types/jest~30.0.0Update only
    expect~30.0.0Update only
    @jest/globals~30.0.0Update only
    jest-jasmine2~30.0.0Update only
    jest-environment-jsdom~30.0.0Update only
    babel-jest~30.0.0Update only
    @swc/jest~0.2.38Update only
  • 21.0.x

  • remove-tsconfig-option-from-jest-executor

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

    Version: 21.0.0-beta.10

    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:

    apps/myapp/project.json
    1{ 2 "targets": { 3 "test": { 4 "executor": "@nx/jest:jest", 5 "options": { 6 "jestConfig": "apps/myapp/jest.config.ts", 7 "tsConfig": "apps/myapp/tsconfig.spec.json" 8 } 9 } 10 } 11} 12

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

    nx.json
    1{ 2 "targetDefaults": { 3 "test": { 4 "executor": "@nx/jest:jest", 5 "options": { 6 "jestConfig": "{projectRoot}/jest.config.ts", 7 "tsConfig": "{projectRoot}/tsconfig.spec.json" 8 } 9 } 10 } 11} 12

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

    nx.json
    1{ 2 "targetDefaults": { 3 "@nx/jest:jest": { 4 "options": { 5 "jestConfig": "{projectRoot}/jest.config.ts", 6 "tsConfig": "{projectRoot}/tsconfig.spec.json" 7 } 8 } 9 } 10} 11

    replace-getJestProjects-with-getJestProjectsAsync-v21

    Replace usage of `getJestProjects` with `getJestProjectsAsync`.

    Version: 21.0.0-beta.9

    Replace Usage of getJestProjects with getJestProjectsAsync

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

    Sample Code Changes

    jest.config.ts
    1import { getJestProjects } from '@nx/jest'; 2 3export default { 4 projects: getJestProjects(), 5}; 6
  • 20.0.x

  • replace-getJestProjects-with-getJestProjectsAsync

    Replace usage of `getJestProjects` with `getJestProjectsAsync`.

    Version: 20.0.0-beta.5

    Replace Usage of getJestProjects with getJestProjectsAsync

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

    Sample Code Changes

    jest.config.ts
    1import { getJestProjects } from '@nx/jest'; 2 3export default { 4 projects: getJestProjects(), 5}; 6
  • 19.6.x

  • 19.6.0-package-updates

    Version: 19.6.0-beta.1

    Packages

    NameVersionAlways Add to package.json
    jest~29.7.0Update only
    @types/jest~29.5.12Update only
    expect~29.7.0Update only
    @jest/globals~29.7.0Update only
    jest-jasmine2~29.7.0Update only
    jest-environment-jsdom~29.7.0Update only
    babel-jest~29.7.0Update only
  • 19.2.x

  • 19.2.0-package-updates

    Version: 19.2.0-beta.0

    Packages

    NameVersionAlways Add to package.json
    @swc/jest~0.2.36Update only