我有一个场景,我有一个函数,我们不想将其包含在 Jest 测试覆盖范围中,但我们仍然希望将其包含在 JSDoc 文档生成中。以下面的函数为例:
/**
* This is a test function description
* @function
*/
/* istanbul ignore next */
export const myTestFunction = () => {
console.log("testing");
return true;
};
我希望该函数不包含在 Jest 代码覆盖率统计中,但我仍然希望处理 JSDoc 并将其包含在通过 JSDoc 生成的文档中。添加 istanbul 注释似乎会导致两个函数都被忽略。是否有其他方法告诉 Jest 排除此方法?
我认为问题是 JSDoc 块不在函数(导出常量)的正上方,并且注释行在那里。不确定您的现实世界场景,尝试建议解决方法。一种选择是将这些类型的函数放入一个单独的文件中,并将该文件添加到collectCoverageFrom 的 Jest 配置中,并在 glob 中包含一个负文件。
collectCoverageFrom: [
'<rootDir>/**/*.ts',
'!<rootDir>/**/newfunctions.ts', // This is the file you moved the functions into
'!<rootDir>/**/*.module.ts'
],
老问题,也许这在三年前不起作用,但我发现简单地交换评论就可以了。
/* istanbul ignore next */
/**
* This is a test function description
* @function
*/
export const myTestFunction = () => {
console.log("testing");
return true;
};