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.
The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code before the jQuery library file has loaded. Therefore make sure that you're executing the jQuery code only after jQuery library file has finished loading.
To solve this error, we simply add the jQuery CDN link or downloaded jQuery path link inside the head section. Example: This example resolves the error by adding the required CDN link inside the <script> tag.
The Javascript ReferenceError occurs when referencing a variable that does not exist or has not yet been initialized in the current scope.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With