Search code examples
javascriptjquerykarma-runner

Karma: uncaught ReferenceError $ is not defined


I have seen many other answers on this site but none of them worked for me.

The problem: I need to load jQuery with an URL, not with a local path; and I think I can't add thoose to "files" on karma.conf.js.

Everything seems to be fine, but when I try to use karma to test it, it returns: Uncaught ReferenceError: $ is not defined.

The order of the scripts is fine in the two .html we use.


Solution

  • Simple include the jQuery path in the karma.conf.js (as for Karma 0.12 at least):

    module.exports = function(config) {
      config.set({
    
        files: [
          'https://code.jquery.com/jquery-1.11.2.min.js'
          ...
        ],
    
        ...
      });
    };
    

    I've tested it yesterday because I needed a similar thing for AngularJS.