【问题标题】:Jest :No test found开玩笑:没有找到测试
【发布时间】:2019-12-11 21:02:58
【问题描述】:

我正在尝试使用npm test 对我的项目进行一些集成测试,我的目录如下:

Main_directory==>tests==>integration==>auth.test.js 和 bar.test.js

在我的 package.json 中,我有这个:

"scripts": {
    "test": "jest --watchAll --verbose"
  },

当我执行代码 npm test 时,我在终端上遇到了这个令人难以置信的错误:

No tests found

In G:\main_directory
  35 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 5 matches
  testPathIgnorePatterns: \\node_modules\\ - 35 matches
Pattern:  - 0 matches

您对如何让一切恢复正常并运行一些流畅的集成测试有任何想法吗?

【问题讨论】:

    标签: javascript jestjs integration-testing


    【解决方案1】:

    您正在匹配文件夹 __tests__,但您说您的测试位于 test 文件夹中。因此,要么将测试所在的文件夹名称更改为 __test__,要么在您的 jest 配置中更改名称。

    【讨论】:

    • 如果我修改文件夹名称,它根本不会改变任何东西。只是想知道如何在 jest config 中更改名称。它应该发生在 jest/jest-config/package.json 中吗?
    • 配置 jest 的方法有很多。查看他们的documentation。你可能想修改testMatch
    • 在 Jest-config/build/valid.config.js 中,testMatch 代码如下:testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'] 恐怕我无法理解它。
    • 将 "jest": { "testMatch": ['**/tests/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'] } 添加到您的 package.json,如我刚刚链接的文档中所述
    • 我在主包中添加了add "jest": { "testMatch": ['**/tests/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'] },但还没有运气。
    猜你喜欢
    • 2017-11-28
    • 2021-03-19
    • 2018-12-09
    • 2021-01-01
    • 2018-09-10
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多