Search code examples
javascriptnode.jsgruntjsjasminex-editable

Error: Unknown type: typeaheadjs while running from grunt jasmine:coverage


I'm testing edit in place module and I have this in my spec file:

if (typeof module !== 'undefined' && module.exports) {
    var jsdom = require('jsdom').jsdom;
    global.document = jsdom('<html></html>', {});
    global.window = document.defaultView;
    global.jQuery = global.$ = global.window.jQuery = require('jquery');
    global.navigator = {
        userAgent: ''
    };
    $.platform = $.platform || {};

    require('../runtime/platform/js/modules/platform.editInPlace.js');
    require('../runtime/platform/js/modules/platform.formSupport.js');
    require('../runtime/vendor/parsleyjs/2.2.0-rc1/dist/parsley.js');
    require('../runtime/vendor/bootstrap/3.1.1/js/bootstrap.js');
    require('../runtime/vendor/x-editable/1.5.1/bootstrap3-editable/js/bootstrap-editable.js');
    require('../runtime/vendor/typeaheadjs/0.9.3/typeahead.js');
    require('../runtime/vendor/x-editable/1.5.1/inputs-ext/typeaheadjs/typeaheadjs.js');
    require('../runtime/platform/js/modules/platform.utility.js');
}

when I'm running grunt test:coverage (using instanbul) it throw exception (when I'm initializing edit in place type typaheadjs).

 encountered a declaration exception......×
 Error: Unknown type: typeaheadjs in file:///C:/Launchpad/synergy/src/main/resources/runtime/vendor/jquery/2.1.4/jquery.js (line 250) (1)

(line 250 is error function that throw exception with specified message)

but it work fine when I call that spec from node when I add this code:

function describe(str, callback) {
    callback();
}
function it(str, callback) {
    callback();
}
function expect() {
    return {toEqual: function() {}};
}

Any clue why I got this error when I'm running jasmine from grunt?

EDIT:

I've included console.log in both typeahead files and only the first one shows up when I run from grunt, it show both when I'm running from node.


Solution

  • I was executing the spec using phantomjs so the code inside:

    if (typeof module !== 'undefined' && module.exports) {
    
    }
    

    was never executed, to add typeaheadjs.js I've needed to add vendor file inside grunt file.