从JavaScript代码覆盖中排除函数(不是整个文件)

Mar*_* N. 12 jasmine karma-runner istanbul

我正在用Jasmine创建一些单元测试,而我正在使用的测试运行器是Karma.我还使用karma-coverage插件检查这些测试规范的代码覆盖率.

我想知道是否有任何方法可以从代码覆盖范围本身以及Karma报告(实际上是伊斯坦布尔)中排除某些功能.我想如果第一个问题解决了,那么第二个问题就解决了.

很确定没有明显的方法可以做到这一点,因为我也在伊斯坦布尔看过(业力覆盖使用它),但也许你们中的一些人之前遇到过这种情况.

Mar*_* N. 14

似乎伊斯坦布尔背后的人已经增加了对覆盖范围分析忽略特定代码部分的支持.真有用!

更多信息:https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md


Mah*_*rus 9

使用以下代码行忽略覆盖代码。

/* istanbul ignore if */      ---skips the "if thing" in the source code
/* istanbul ignore else */    ---skips the "else thing" in the source code
/* istanbul ignore next */    ---skips the "next thing" in the source code
Run Code Online (Sandbox Code Playgroud)