-
Notifications
You must be signed in to change notification settings - Fork 0
单元测试
JohnieXu edited this page Jun 26, 2022
·
4 revisions
jest 中使用 istanbul 进行代码覆盖率测试教程:https://www.zeljkovic.sh/generating-code-coverage-report-in-jest/
jest.config.js
配置文件
module.exports = {
coverageDirectory: './coverage/', // 本地生成的测试结果文件(不保存至 git 仓库)
coverageThreshold: { // 覆盖率条件限制(各项指标未达到视为测试不通过)
global: {
statements: 100,
branches: 95,
functions: 100,
lines: 100,
},
},
}
执行命令npm run coverage
,输出的统计结果位于coverage/lcov-report
- 注释掉无关逻辑
/* istanbul ignore next */
或/* istanbul ignore if */
- 针对反馈的未覆盖场景添加更多测试用例