Jest: Ignore lines for code coverage

Nahush Farkande picture Nahush Farkande · Aug 3, 2016 · Viewed 23.7k times · Source

In Jest, is there any way to ignore code for test coverage? I tried using

/* istanbul ignore next */

But it doesn't seem to work.

Answer

ilyar picture ilyar · May 30, 2017

It works.

(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);

Sample project https://github.com/ilyar/sandbox/tree/master/jest