javascript 业力:未捕获的 ReferenceError $ 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28973220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 09:51:10  来源:igfitidea点击:

Karma: uncaught ReferenceError $ is not defined

javascriptjquerykarma-runner

提问by dquijada

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.

问题:我需要使用 URL 加载 jQuery,而不是使用本地路径;我想我不能将 thoose 添加到 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.

一切似乎都很好,但是当我尝试使用 karma 来测试它时,它返回:Uncaught ReferenceError: $ is not defined。

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

在我们使用的两个 .html 中,脚本的顺序很好。

回答by MarcoL

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

简单地包含 jQuery 路径karma.conf.js(至少对于 Karma 0.12):

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.

我昨天测试了它,因为我需要 AngularJS 类似的东西。