5

假设我有以下代码:

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);
        });
    });
});
4

1 回答 1

2

伊斯坦布尔让您在此处的代码中明确定义自己的自定义忽略

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

希望它会有所帮助

于 2015-02-09T19:46:31.343 回答