Run Jest unit tests.
@nx/jest
Package reference
Here is a list of all the executors, generators and migrations available from this package.
Executors
Generators
initInternal
Initialize the
@nx/jest
plugin.configurationInternal
Add Jest configuration to a project.
Convert existing Jest project(s) using
@nx/jest:jest
executor to use@nx/jest/plugin
.
Migrations
21.3.x
21.0.x
20.0.x
19.6.x
19.2.x
rename-test-path-pattern
Rename the CLI option `testPathPattern` to `testPathPatterns`.
Requires
Name | Version |
---|---|
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:
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:
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:
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:
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
Requires
Name | Version |
---|---|
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
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
Packages
Name | Version | Always Add to package.json |
---|---|---|
jest | ~30.0.0 | Update only |
@types/jest | ~30.0.0 | Update only |
expect | ~30.0.0 | Update only |
@jest/globals | ~30.0.0 | Update only |
jest-jasmine2 | ~30.0.0 | Update only |
jest-environment-jsdom | ~30.0.0 | Update only |
babel-jest | ~30.0.0 | Update only |
@swc/jest | ~0.2.38 | Update only |
remove-tsconfig-option-from-jest-executor
Remove the previously deprecated and unused `tsConfig` option from the `@nx/jest:jest` executor.
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:
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:
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:
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`.
Replace Usage of getJestProjects
with getJestProjectsAsync
Replaces the usage of the removed getJestProjects
function with the getJestProjectsAsync
function.
Sample Code Changes
1import { getJestProjects } from '@nx/jest';
2
3export default {
4 projects: getJestProjects(),
5};
6
replace-getJestProjects-with-getJestProjectsAsync
Replace usage of `getJestProjects` with `getJestProjectsAsync`.
Replace Usage of getJestProjects
with getJestProjectsAsync
Replaces the usage of the deprecated getJestProjects
function with the getJestProjectsAsync
function.
Sample Code Changes
1import { getJestProjects } from '@nx/jest';
2
3export default {
4 projects: getJestProjects(),
5};
6
19.6.0-package-updates
Packages
Name | Version | Always Add to package.json |
---|---|---|
jest | ~29.7.0 | Update only |
@types/jest | ~29.5.12 | Update only |
expect | ~29.7.0 | Update only |
@jest/globals | ~29.7.0 | Update only |
jest-jasmine2 | ~29.7.0 | Update only |
jest-environment-jsdom | ~29.7.0 | Update only |
babel-jest | ~29.7.0 | Update only |
19.2.0-package-updates
Packages
Name | Version | Always Add to package.json |
---|---|---|
@swc/jest | ~0.2.36 | Update only |