Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Jest finds no test files and exits with code 1

ErrorNo tests found, exiting with code 1

Short answer

Jest exits with code 1 when its file scan matches nothing. List what it would run with jest --listTests. If that is empty, the file names or folders do not match testMatch, roots or rootDir is wrong, or testPathIgnorePatterns hides them. In watch mode, Jest runs only changed files and needs a git or hg repository.

  • Applies to Jest 30, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask Jest which test files it sees, with the same options you normally pass.

    npx jest --listTests
  2. 2Match what you see, then jump to its fix

    1. 1--listTests prints nothing though test files existFile names or folders do not match testMatchFix
    2. 2Tests live outside the folder Jest scansroots or rootDir points at the wrong folderFix
    3. 3Tests sit under a path matched by an ignore patterntestPathIgnorePatterns hides the filesFix
    4. 4npm test works with --watchAll but not with --watch, or no changed files existWatch mode in a folder that is not a git or hg repositoryFix
    5. 5A new package with no tests yet fails the CI stepExit code 1 is wanted behaviour for an empty projectFix

What does the error look like?

  • No tests found, exiting with code 1

Cause 1 of 5

File names or folders do not match testMatch

1Check

By default Jest runs files in __tests__ folders and files named *.test.* or *.spec.* with js, jsx, ts, tsx (and mjs, cjs, mts, cts) extensions.

npx jest --showConfig | grep -A4 testMatch

2Fix

Rename the files to match, or set testMatch in the config.

// jest.config.js
module.exports = {
  testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
};

3Verify

The file now appears.

npx jest --listTests

Confirmed by jestjs.io

Did this fix it?

Cause 2 of 5

roots or rootDir points at the wrong folder

1Check

Jest searches the directories in roots, and <rootDir> defaults to the config file's directory, else the package.json directory, else the current directory.

npx jest --showConfig | grep -E "rootDir|roots"

2Fix

Run Jest from the project root, or set roots and rootDir to include the test folder.

module.exports = {
  rootDir: '.',
  roots: ['<rootDir>/src'],
};

3Verify

List the tests again.

npx jest --listTests

Confirmed by jestjs.io

Did this fix it?

Cause 3 of 5

testPathIgnorePatterns hides the files

1Check

A match with testPathIgnorePatterns skips the file; the default is /node_modules/.

npx jest --showConfig | grep -A3 testPathIgnorePatterns

2Fix

Remove or narrow the pattern that matches your test path.

module.exports = {
  testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/build/'],
};

3Verify

List the tests again.

npx jest --listTests

Confirmed by jestjs.io

Did this fix it?

Cause 4 of 5

Watch mode in a folder that is not a git or hg repository

1Check

--watch reruns tests related to changed files. The Jest CLI docs say identifying changed files (--onlyChanged) works only in a git or hg repository.

git status

2Fix

Use --watchAll to run all tests, or initialise a repository.

npx jest --watchAll

3Verify

Jest now lists and runs the tests.

npx jest --watchAll=false

Confirmed by jestjs.io

Did this fix it?

Cause 5 of 5

Exit code 1 is wanted behaviour for an empty project

1Check

The CLI docs say without --passWithNoTests Jest errors when nothing matches.

npx jest --listTests

2Fix

Add the flag for packages that may have no tests yet.

npx jest --passWithNoTests

3Verify

The command exits with code 0.

npx jest --passWithNoTests; echo $?

Confirmed by jestjs.io

Did this fix it?

How do I stop it coming back?

  • Run jest --listTests after changing config or moving folders.
  • Name tests *.test.* or put them in __tests__.
  • Run Jest from the folder that holds package.json.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.