【问题标题】:Jest - cannot find the tests开玩笑 - 找不到测试
【发布时间】:2021-01-01 13:19:32
【问题描述】:

由于某种奇怪的原因,我无法运行我的笑话测试。我在这里错过了什么吗?

我已经尝试过 __test__ 和 __tests__

文件夹结构:

Package.json:


  "scripts": {
    "start": "ts-node-dev --poll src/index.ts",
    "test": "jest watchAll --no-cache"
  },
  "jest": {
    "preset": "ts-jest",
    "testEnvironment": "node",
    "setupFilesAfterEnv": [
      "./src/test/setup.ts"
    ]
  },

错误:

> auth@1.0.0 test E:\cultor-microservices\auth
> jest watchAll --no-cache

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In E:\cultor-microservices\auth
  15 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 1 match
  testPathIgnorePatterns: \\node_modules\\ - 15 matches
  testRegex:  - 0 matches
Pattern: watchAll - 0 matches

【问题讨论】:

  • 您可以在输出中看到它要查找的内容:**/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x)。 __tests__ 应该可以工作,__test__ 不会,所以给minimal reproducible example 一些应该可以工作的东西。

标签: node.js typescript unit-testing jestjs ts-jest


【解决方案1】:

这是一个愚蠢的错误,我忘记了测试脚本中watchAll前面的“--” package.json:

  "scripts": {
    "start": "ts-node-dev --poll src/index.ts",
    "test": "jest --watchAll --no-cache"      // <-- here 
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 2018-09-10
    • 2021-03-19
    • 2020-12-21
    • 2018-12-09
    • 1970-01-01
    • 2018-04-05
    相关资源
    最近更新 更多