Skip to content

Jest is a JavaScript testing framework.

The @nx/jest plugin adds inferred Jest targets, a Jest configuration generator, and CI-ready test splitting.

You can use Jest with Nx without the plugin and still get task caching, task orchestration, and the project graph.

The @nx/jest plugin supports the following package versions.

PackageSupported Versions
jest^29.0.0 || ^30.0.0

Nx generators install the latest supported versions automatically when scaffolding new projects.

Terminal window
nx add @nx/jest

Verify the inferred test target in the project details view:

Terminal window
nx show project my-app

Generate Jest configuration for an existing project:

Terminal window
nx g @nx/jest:configuration --project=my-app

Replace my-app with your project name.

The generator accepts framework-specific options. Pass the right flags for your project type:

Terminal window
nx g @nx/jest:configuration --project=my-react-lib --supportTsx

Enables the JSX/TSX transform so Jest can process React components.

See the full configuration generator reference for all options.

Run tests:

Terminal window
nx test my-app

Watch for changes:

Terminal window
nx test my-app --watch

Run a specific file (positional argument or --testFile):

Terminal window
nx test my-app ./path/to/spec/file/user-profile.spec.ts
nx test my-app --testFile user-profile.spec.ts

Collect coverage:

Terminal window
nx test my-app --coverage

Snapshot example:

describe('userProfile', () => {
it('matches the saved snapshot', () => {
expect(renderUserProfile()).toMatchSnapshot();
});
});

Update snapshots with -u/--updateSnapshot and check snapshot files into source control.

The @nx/jest plugin infers tasks for any project with a Jest configuration file:

  • jest.config.js
  • jest.config.ts
  • jest.config.mjs
  • jest.config.mts
  • jest.config.cjs
  • jest.config.cts

Configure the plugin in nx.json:

nx.json
{
"plugins": [
{
"plugin": "@nx/jest/plugin",
"options": {
"targetName": "test"
}
}
]
}
OptionTypeDefaultDescription
targetNamestringtestName of the inferred Jest target.
ciTargetNamestringnoneCreates a CI-only target for atomized test tasks.
ciGroupNamestringnoneCustom group name for atomized tasks in Nx Cloud/UI.
disableJestRuntimebooleantrueWhen true, Nx skips creating the Jest runtime and computes inputs/outputs itself. Set to false to enable the Jest runtime.
useJestResolverbooleantrue when runtime is enabledWhether to use Jest's resolver for resolving config file references as task inputs. Follows symlinks and honors custom moduleDirectories/modulePaths. Faster path-based classification is used when false.

disableJestRuntime defaults to true because the plugin treats it as enabled only when options.disableJestRuntime !== false. This reduces computation time for inferred tasks; set it to false if you need Jest runtime inference.

Use two plugin entries to separate unit and E2E Jest tasks, and enable CI splitting for E2E:

nx.json
{
"plugins": [
{
"plugin": "@nx/jest/plugin",
"exclude": ["e2e/**/*"],
"options": {
"targetName": "test"
}
},
{
"plugin": "@nx/jest/plugin",
"include": ["e2e/**/*"],
"options": {
"targetName": "e2e",
"ciTargetName": "e2e-ci"
}
}
]
}

ciTargetName enables split E2E tasks so each test file runs as its own CI task with better caching and retries. Use ciGroupName if you want a custom group label.

Open the project details view in Nx Console or run:

Terminal window
nx show project my-app

In CI, Nx runs nx affected to rebuild and retest only the projects a change touches, and caches results to skip repeated work.

For a complete pipeline, see Set up CI.