twitter-bootstrap Karma:未捕获的 ReferenceError:未定义 jQuery

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18242580/
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-21 17:58:46  来源:igfitidea点击:

Karma: Uncaught ReferenceError: jQuery is not defined

jquerytwitter-bootstrapkarma-runner

提问by Karan

I am running Karma on my yeoman based angularjs app.

我在基于 yeoman 的 angularjs 应用程序上运行 Karma。

I get the following error when running "grunt karma":

运行“grunt karma”时出现以下错误:

Chrome 28.0 (Mac) ERROR
    Uncaught ReferenceError: jQuery is not defined
    at myNgApp/admin/app/scripts/bootstrap.min.js:6
Chrome 28.0 (Mac): Executed 0 of 0 ERROR (0.206 secs / 0 secs)
Chrome 28.0 (Mac) ERROR
    Uncaught ReferenceError: jQuery is not defined
    at myNgApp/admin/app/scripts/bootstrap.min.js:6
Chrome 28.0 (Mac): Executed 0 of 0 ERROR (0.206 secs / 0 secs)

When I launch the app on my browser via "grunt server", everything seems fine. There are no errors on the console either.

当我通过“grunt server”在我的浏览器上启动应用程序时,一切似乎都很好。控制台上也没有错误。

My index.htmlalso imports jquery.min.jsbefore any other JavaScript file. Any idea what is going on?

Myindex.html也在jquery.min.js任何其他 JavaScript 文件之前导入。知道发生了什么吗?

Update:I have a feeling the the command grunt karmais looking through all the files in my scripts directory. Bootstrap is one of the first ones, and it probably loads that before jQuery, and hence the error.

更新:我有一种感觉,该命令grunt karma正在查看我的脚本目录中的所有文件。Bootstrap 是第一个,它可能在 jQuery 之前加载,因此错误。

If this is the case, how do I stop this?

如果是这种情况,我该如何阻止?

回答by Peter Ahlers

Did you load jQuery in the karma.conf.js?

您是否在 karma.conf.js 中加载了 jQuery?

This is how my list looks:

这是我的清单的样子:

// list of files / patterns to load in the browser
files: [
  'app/bower_components/jquery/jquery.js',
  'app/bower_components/angular/angular.js',
  'app/bower_components/moment/moment.js',
  'app/bower_components/underscore/underscore.js',
  'app/bower_components/angular-mocks/angular-mocks.js',
  'app/bower_components/angular-resource/angular-resource.js',
  'app/bower_components/angular-route/angular-route.js',
  'app/bower_components/angular-sanitize/angular-sanitize.js',
  'app/bower_components/ngInfiniteScroll/ng-infinite-scroll.js',
  'app/bower_components/parametrizedLocation/dist/parametrizedLocation.js',
  'app/bower_components/angular-cookies/angular-cookies.js',
  'app/bower_components/angular-translate/angular-translate.js',
  'app/bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.js',
  'app/bower_components/angular-translate-storage-cookie/angular-translate-storage-cookie.js',
  'app/bower_components/angular-translate-storage-local/angular-translate-storage-local.js',
  'app/scripts/*.js',
  'app/scripts/**/*.js',
  'test/mock/**/*.js',
  'test/spec/**/*.js'
],