开玩笑 - 有没有办法检查测试覆盖率的百分比?

jest - Is there a way to check percentage of test coverage?

我使用以下命令 运行 我的测试并获得覆盖率报告:

jest --coverage

现在我想检查脚本文件中的覆盖率是否超过 90%。我该怎么办?

您可以在 Jest 配置中使用 coverageThreshold 选项:

https://jestjs.io/docs/en/configuration#coveragethreshold-object

{
  ...
  "jest": {
    "coverageThreshold": {
      "global": {
        "branches": 50,
        "functions": 50,
        "lines": 50,
        "statements": 50
      }
    }
  }
}