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.
Requirements
Section titled “Requirements”The @nx/jest plugin supports the following package versions.
| Package | Supported Versions |
|---|---|
jest | ^29.0.0 || ^30.0.0 |
Nx generators install the latest supported versions automatically when scaffolding new projects.
Add to an existing workspace
Section titled “Add to an existing workspace”nx add @nx/jestVerify the inferred test target in the project details view:
nx show project my-appAdd Jest to a project
Section titled “Add Jest to a project”Generate Jest configuration for an existing project:
nx g @nx/jest:configuration --project=my-appReplace my-app with your project name.
The generator accepts framework-specific options. Pass the right flags for your project type:
nx g @nx/jest:configuration --project=my-react-lib --supportTsxEnables the JSX/TSX transform so Jest can process React components.
nx g @nx/jest:configuration --project=my-angular-lib --setupFile=angularConfigures jest-preset-angular and keeps Angular snapshot serializers enabled.
nx g @nx/jest:configuration --project=my-node-lib --testEnvironment=nodeUses the node test environment instead of the default jsdom.
See the full configuration generator reference for all options.
Local development
Section titled “Local development”Run tests:
nx test my-appWatch for changes:
nx test my-app --watchRun a specific file (positional argument or --testFile):
nx test my-app ./path/to/spec/file/user-profile.spec.tsnx test my-app --testFile user-profile.spec.tsCollect coverage:
nx test my-app --coverageSnapshot example:
describe('userProfile', () => { it('matches the saved snapshot', () => { expect(renderUserProfile()).toMatchSnapshot(); });});Update snapshots with -u/--updateSnapshot and check snapshot files into source control.
Configuration
Section titled “Configuration”Task inference
Section titled “Task inference”The @nx/jest plugin infers tasks for any project with a Jest configuration file:
jest.config.jsjest.config.tsjest.config.mjsjest.config.mtsjest.config.cjsjest.config.cts
Plugin options
Section titled “Plugin options”Configure the plugin in nx.json:
{ "plugins": [ { "plugin": "@nx/jest/plugin", "options": { "targetName": "test" } } ]}| Option | Type | Default | Description |
|---|---|---|---|
targetName | string | test | Name of the inferred Jest target. |
ciTargetName | string | none | Creates a CI-only target for atomized test tasks. |
ciGroupName | string | none | Custom group name for atomized tasks in Nx Cloud/UI. |
disableJestRuntime | boolean | true | When true, Nx skips creating the Jest runtime and computes inputs/outputs itself. Set to false to enable the Jest runtime. |
useJestResolver | boolean | true when runtime is enabled | Whether 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.
Unit and e2e configurations
Section titled “Unit and e2e configurations”Use two plugin entries to separate unit and E2E Jest tasks, and enable CI splitting for E2E:
{ "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.
View inferred tasks
Section titled “View inferred tasks”Open the project details view in Nx Console or run:
nx show project my-appSet up CI
Section titled “Set up CI”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.