【问题标题】:Jest --findRelatedTests not finding related testJest --findRelatedTests 没有找到相关的测试
【发布时间】:2020-05-22 08:08:59
【问题描述】:

当我运行命令 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 就可以了。

【问题讨论】:

  • 你试过了吗? jest pathoffile
  • 如果我提供测试文件就可以了,但这不是我想要的。因为我想让 Jest 找到给定组件的相关测试
  • 然后你可以把__tests__文件夹中的所有测试文件放到自动拾取。
  • 您找到解决方案了吗?

标签: reactjs typescript jestjs


【解决方案1】:

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

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

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

相关信息:

【讨论】:

    猜你喜欢
    • 2019-12-22
    • 2017-10-19
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    • 2021-06-07
    • 2021-01-12
    • 2014-04-23
    • 1970-01-01
    相关资源
    最近更新 更多