最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Karma: uncaught ReferenceError $ is not defined - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question asked Mar 10, 2015 at 20:12 dquijadadquijada 1,6993 gold badges14 silver badges19 bronze badges 5
  • Can you delay the test execution? in protractor you'd do something like ptor.sleep(2000) before/in your test blocks – Christopher Marshall Commented Mar 10, 2015 at 20:18
  • I don't know how to do it, or what is protractor. Sorry, this is an assignment in the Uni, and we aren't really familiar with this tools. – dquijada Commented Mar 10, 2015 at 20:28
  • We use Karma and Gulp for this (with Mocha and Chai, if that matters) – dquijada Commented Mar 10, 2015 at 20:29
  • I believe you can just add the external url to the files block in your karma.config.js (unsure) stackoverflow.com/questions/20938320/… – Christopher Marshall Commented Mar 10, 2015 at 20:56
  • Working: stackoverflow.com/q/70940235/7186739 – Muhammad Bilal Commented Feb 2, 2022 at 15:46
Add a comment  | 

1 Answer 1

Reset to default 30

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.

发布评论

评论列表(0)

  1. 暂无评论