Skip to main content
The @nx/jest plugin integrates Jest into your Nx workspace. It provides the jest executor for running unit tests, infers test targets from jest.config.ts files automatically, and supports SWC for faster TypeScript transforms.

Installation

Or install manually:

What the plugin provides

Executors

The jest executor runs your test suite with full Nx integration: caching, affected detection, and distributed execution.

Generators

Add Jest configuration to any existing project. Migrate executor-based projects to inferred task mode.

Inferred tasks

Detects jest.config.ts (or .js, .mjs, .cjs) files and infers a test target automatically.

Generators

configuration

Add Jest configuration to an existing project. This creates a jest.config.ts file and wires up the test target.
Use SWC instead of ts-jest for faster transforms:
Use Babel as the compiler:

convert-to-inferred

Migrate existing projects that use the @nx/jest:jest executor to use the inferred task plugin (@nx/jest/plugin).

Executors

jest

Run Jest unit tests for a project. Supports all standard Jest CLI flags and adds Nx caching.
Run tests:

Inferred tasks

When @nx/jest/plugin is registered in nx.json, Nx detects jest.config.ts (or .js, .mjs, .cjs, .cts, .mts) files and automatically infers a test target for each project that has one.
With inferred tasks, removing the test target from project.json entirely is safe. Nx reads the Jest configuration directly from jest.config.ts.
Inferred task caching is based on the inputs defined in your jest.config.ts and the project’s source files. Use nx show project myproject to inspect the inferred targets.

Configuration examples

jest.config.ts with ts-jest

jest.config.ts with SWC

SWC provides significantly faster TypeScript transforms compared to ts-jest:

jest.config.ts for React components

Workspace-level jest.preset.js

Shared preset used by all projects:

Running affected tests

One of Nx’s most powerful features is running only the tests affected by recent changes:
Combine nx affected with Nx Cloud for distributed test execution across multiple CI agents, dramatically reducing total CI time.