首页 > 解决方案 > Jest --findRelatedTests 没有找到相关的测试

问题描述

当我运行命令时,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

但是我确实准备好了文件:

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

为什么 Jest 找不到相关的测试?跑步jest工作得很好。

标签: reactjstypescriptjestjs

解决方案


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

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

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

相关信息:


推荐阅读