Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest --findRelatedTests not finding related test

When I run the command jest --bail --findRelatedTests src/components/BannerSet/BannerSet.tsx I get the following message:

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
No files found in C:\Users\user\code\repo.
Make sure Jest's configuration does not exclude this directory.
To set up Jest, make sure a package.json file exists.
Jest Documentation: facebook.github.io/jest/docs/configuration.html
Pattern: .\\src\\components\\BannerSet\\BannerSet.tsx - 0 matches

However I do have the files ready:

src/components/BannerSet/BannerSet.test.tsx
src/components/BannerSet/BannerSet.tsx

Why cant Jest find the related tests? Running just jest works perfectly fine.

like image 611
Gilian Avatar asked Nov 15 '22 17:11

Gilian


1 Answers

If you are using the roots configuration ensure you include your source directory in the list of folders.

I ran into this issue and found it was because I was using the roots option in my jest configuration and was only referencing the test folder. The below issue and roots documentation point out:

roots is used by the internals of Jest to locate test files and source files

Related information:

  • Docs: https://jestjs.io/docs/configuration#roots-arraystring
  • Issue: https://github.com/facebook/jest/issues/11527
like image 169
CortexCompiler Avatar answered Jan 08 '23 14:01

CortexCompiler