Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Say I have the following code:

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

        },

        stuff: function() {

        }
    };
});

Istanbul reports that only 1/3 functions have been tested. Which is somewhat true as I have only run a test against main.initialize.

How can I get Istanbul to ignore the function used for define callback?

Edit: Additional Gruntfile.js config

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
        }
    }
}

Edit: Example Spec

define([
    'app/main'
], function(main) {
    describe('app/main', function() {
        it('initailize should not error', function() {
            expect(main.initialize()).toBe(undefined);
        });
    });
});
like image 864
jshthornton Avatar asked Oct 31 '22 10:10

jshthornton


1 Answers

Istanbul let's you define your own custom ignores explicitly in your code here

You may use /* istanbul ignore define */ at the top of your file to prevent define(...) from been checked.

Hope it'll help

like image 111
Santiago Bernabé Avatar answered Nov 15 '22 05:11

Santiago Bernabé