Jest --findRelatedTests 未找到相关测试

Gil*_*ian 6 typescript reactjs jestjs

当我运行命令时,jest --bail --findRelatedTests src/components/BannerSet/BannerSet.tsx 我收到以下消息:

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
Run Code Online (Sandbox Code Playgroud)

不过我已经准备好了文件:

src/components/BannerSet/BannerSet.test.tsx
src/components/BannerSet/BannerSet.tsx
Run Code Online (Sandbox Code Playgroud)

为什么 Jest 找不到相关测试?跑步jest效果非常好。

Cor*_*ler 1

如果您使用该roots配置,请确保将源目录包含在文件夹列表中。

我遇到了这个问题,发现这是因为我roots在玩笑配置中使用了该选项,并且仅引用了该test文件夹。以下问题和根源文档指出:

Jest 内部使用root来定位测试文件 源文件

相关信息: