我试图给Jest/伊斯坦布尔提供忽略提示,但是它们被完全忽略了--报道没有改变。例如:
/* istanbul ignore if */
if (process.env.NODE_ENV === 'development') {
const fromStateStr = JSON.stringify(fromState);
const toStateStr = JSON.stringify(toState);
console.log(
`RouterStore.transition(${fromStateStr}, ${toStateStr})`
);
}我也在不同的线路上尝试过/* istanbul ignore next */,但是没有改变。我是不是错过了什么环境?这是我的Jest配置:
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"setupFiles": [
"./test/test-shim.ts",
"./test/test-setup.ts"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/test/"
],
"coverageThreshold": {
"global": {
"branches": 90,
"functions": 95,
"lines": 95,
"statements": 95
}
},
"collectCoverage": true,
"mapCoverage": true
}发布于 2018-02-12 15:09:26
原因是TypeScript编译器删除了所有注释,包括伊斯坦布尔提示。因此,测试忽略了所有提示。必须将"removeComments": false添加到tsconfig.json以使其工作。
谢谢卢西恩指出了这一点。
https://stackoverflow.com/questions/48284724
复制相似问题