我正在开玩笑地测试我的反应组件,并使用HUSKY进行预提交检查。
我在jest.config.js中的配置低于全局阈值
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 90,
statements: 90,
},
},
我有一个用例,其中我正在使用 npm run test---coverage --findRelatedTests 来检查覆盖范围内仅已更改文件的测试用例。
但是上述命令将更改后的文件的测试用例与全局测试用例进行了比较,从而导致出现以下问题
=============================== Coverage summary ===============================
Statements : 5.74% ( 21/366 )
Branches : 8.93% ( 10/112 )
Functions : 1.33% ( 1/75 )
Lines : 6.27% ( 21/335 )
================================================================================
coverage threshold for statements (90%) not met: 5.74%
coverage threshold for branches (80%) not met: 8.93%
coverage threshold for lines (90%) not met: 6.27%
coverage threshold for functions (80%) not met: 1.33%
我想要的是它应该只为更改的文件检查并生成测试覆盖率,而不应该包括所有其他文件,然后比较覆盖率显然很低的情况。
答案 0 :(得分:0)
要测试代码的特定部分,您需要在测试用例中添加“only”关键字,请参见下文:
describe(......, (): void => {
it.only(..........
然后在命令行运行 npm/yarn test src/...url 到这个文档