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)
When I launch the app on my browser via "grunt server", everything seems fine. There are no errors on the console either.
当我通过“grunt服务器”在我的浏览器上启动应用程序时,一切似乎都很好。控制台上也没有错误。
My index.html
also imports jquery.min.js
before any other JavaScript file. Any idea what is going on?
我的index.html还在任何其他JavaScript文件之前导入jquery.min.js。知道发生了什么事吗?
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.
更新:我感觉命令grunt karma正在查看我的脚本目录中的所有文件。 Bootstrap是最早的之一,它可能在jQuery之前加载,因此错误。
If this is the case, how do I stop this?
如果是这种情况,我该如何制止?
1 个解决方案
#1
41
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'
],
#1
41
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'
],