让伊斯坦布尔.js忽略定义(require.js)定义

Getting Istanbul.js to ignore the define (require.js) definition

本文关键字:定义 js require 伊斯坦布尔      更新时间:2023-09-26

假设我有以下代码:

define([
    'a'
], function(a) {
    return {
        initialize: function() {
        },
        stuff: function() {
        }
    };
});

伊斯坦布尔报告说,只有1/3的功能经过测试。这有点正确,因为我只对main.initialize进行了测试.

如何让伊斯坦布尔忽略用于定义回调的函数?

编辑:附加Gruntfile.js配置

jasmine: {
    coverage: {
        src: 'src/assets/js/app/**/*.js',
        options: {
            specs: 'src/assets/js/spec/**/*Spec.js',
            host: 'http://127.0.0.1:8000/',
            template: require('grunt-template-jasmine-istanbul'),
            templateOptions: {
                //files: 'src/assets/js/app/**/*.js',
                coverage: 'bin/coverage/coverage.json',
                report: [
                    {type: 'html', options: {dir: 'src/coverage/html'}},
                    {type: 'text-summary'}
                ],
                template: require('grunt-template-jasmine-requirejs'),
                templateOptions: {
                    requireConfig: {
                        baseUrl: 'src/assets/js',
                        paths: {
                /*          'jquery': 'lib/jquery',
                            'underscore': 'lib/lodash',
                            'text': 'lib/text',
                            'i18n': 'lib/i18n',*/
                        }
                    }
                }

            },
            keepRunner: true
        }
    }
}

编辑:示例规范

define([
    'app/main'
], function(main) {
    describe('app/main', function() {
        it('initailize should not error', function() {
            expect(main.initialize()).toBe(undefined);
        });
    });
});

伊斯坦布尔 让我们在这里的代码中显式定义自己的自定义忽略

您可以使用文件顶部的/* istanbul ignore define */来防止检查define(...)

希望会有所帮助