【问题标题】:How can I know what percentage is covered by my tests?我怎么知道我的测试覆盖了多少百分比?
【发布时间】:2022-02-08 00:39:57
【问题描述】:

我想知道我的测试涵盖了我的项目的多少,我目前正在尝试使用 jest 来做到这一点。

这是我的jest.config.js

module.exports = {
  verbose: true,
  preset: '@vue/cli-plugin-unit-jest',
  transform: {
    '^.+\\.vue$': 'vue-jest',
  },
  jest: {
    coverageThreshold: {
      global: {
        branches: 50,
        functions: 50,
        lines: 50,
        statements: 50,
      },
      './src/components/': {
        branches: 40,
        statements: 40,
      },
      './src/reducers/**/*.js': {
        statements: 90,
      },
      './src/api/very-important-module.js': {
        branches: 100,
        functions: 100,
        lines: 100,
        statements: 100,
      },
    },
  },
}

但是当我尝试运行命令jest --coverage --coverageReporters="json-summary"

我收到错误:bash: jest: command not found 如何解决此错误?

我的 devDependecies 是:

 "eslint-plugin-vue": "^7.0.0",
    "jest": "^27.5.0",
    "jest-cli": "^27.5.0",

【问题讨论】:

  • 如果您看到jest command not found,这仅表示您尚未将jest 添加到您的项目中。运行yarn install jest -D。或npm i jest -D。添加后,您将在控制台中看到覆盖范围(或保存到文件中,具体取决于您运行的命令)。

标签: javascript vue.js jestjs


【解决方案1】:

你的错误是

bash: jest: 找不到命令

这意味着 jest 没有添加到您的项目中/已安装。安装它:npm install --save-dev jest

More information about jest

【讨论】:

    猜你喜欢
    • 2014-05-02
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多