code-coverage - 如何在 Jest 中忽略代码覆盖率行

标签 code-coverage jestjs istanbul

在 Jest 中,有没有办法忽略测试覆盖率的代码? 我尝试使用

/* istanbul ignore next */

但似乎不起作用。

最佳答案

它有效。

(function(global) {
    var defineAsGlobal = true;
    /* istanbul ignore next */
    if(typeof exports === 'object') {
        module.exports = lib;
        defineAsGlobal = false;
    }
    /* istanbul ignore next */
    if(typeof modules === 'object' && typeof modules.define === 'function') {
        modules.define('lib', function(provide) {
            provide(lib);
        });
        defineAsGlobal = false;
    }
    /* istanbul ignore next */
    if(typeof define === 'function') {
        define(function(require, exports, module) {
            module.exports = lib;
        });
        defineAsGlobal = false;
    }
    /* istanbul ignore next */
    defineAsGlobal && (global.lib = lib);
})(this);

示例项目https://github.com/ilyar/sandbox/tree/master/jest

关于code-coverage - 如何在 Jest 中忽略代码覆盖率行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38740165/

相关文章:

android - 如何在 Android 中为 Espresso 测试自定义 Jacoco

node.js - 使用异步函数模拟请求错误

node.js - 当测试用例花费更多时间时, Istanbul 尔与摩卡不会生成覆盖率报告

iphone - gcovr-cobertura

java - IntelliJ 中的代码覆盖率

javascript - Jest 单元测试 module.export 失败?

javascript - 如何模拟在测试模块中导入的变量,它不是函数参数(使用 describe.each 并在每个测试更改模拟值时执行此操作)

angularjs - Jasmine 的代码覆盖率中未涵盖的语句

unit-testing - 暂时获得 Jest 报道,只显示特定文件夹中的文件

node.js - 如何在 Nodejs 中为 Winston 记录器编写单元测试