Karma: Uncaught ReferenceError: jQuery is not defined

Karan picture Karan · Aug 14, 2013 · Viewed 14.9k times · Source

I am running Karma on my yeoman based angularjs app.

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)

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

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

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?

Answer

Peter Ahlers picture Peter Ahlers · Oct 2, 2013

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

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