业力:未捕获ReferenceError:jQuery未定义 [英] Karma: Uncaught ReferenceError: jQuery is not defined

查看:115
本文介绍了业力:未捕获ReferenceError:jQuery未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am running Karma on my yeoman based angularjs app.

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

I get the following error when running "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)

当我通过"grunt服务器"在浏览器中启动该应用程序时,一切似乎都很好.控制台上也没有错误.

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

我的index.html还将jquery.min.js导入到任何其他JavaScript文件之前.知道发生了什么吗?

My index.html also imports jquery.min.js before any other JavaScript file. Any idea what is going on?

更新:我感觉命令grunt karma正在浏览我的脚本目录中的所有文件. Bootstrap是第一个,它可能会在jQuery之前加载它,因此会出现错误.

Update: I have a feeling the the command grunt karma is 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.

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

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

推荐答案

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

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

这是我的列表的样子:

// 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'
],

这篇关于业力:未捕获ReferenceError:jQuery未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆