Reputation: 21
I'm pretty new to angularjs, and I'm trying to test an app using Jasmine and Karma. The tests work fine if I just use the basic framework that Jasmine provides (with SpecRunner.html), but when I try to use Karma I keep getting the same 'module is not defined' message.
My file dependencies in karma.conf.js are as follows:
files: [
'../../js/angular.min.js',
'../../js/angular-sanitize.min.js',
'lib/angular-mocks.js',
'../../js/app.js',
'lib/jasmine-2.4.1/jasmine.js',
'lib/jasmine-2.4.1/jasmine-html.js',
'lib/jasmine-2.4.1/boot.js',
'lib/jquery-1.11.3.min.js',
'spec/spec.js'
]
So far this looks exactly like all the previous karma undefined module questions I've seen on SO, except I'm quite sure that angular-mocks.js is included, file locations are correct, and I'm not using any other framework that might be overriding karma.conf.js. I apologize for asking the same question again, but am I missing something really obvious here?
Upvotes: 2
Views: 875
Reputation: 579
I have had similar issues with Karma in the past. It is picky about the order that you put the dependencies into. For instance, if you are using JQuery and Angular, then Karma will want JQuery before Angular. I see that you placed Angular before all of its submodules, which is great.
I would place the dependencies in this order:
files: [
'lib/jquery-1.11.3.min.js',
'../../js/angular.min.js',
'../../js/angular-sanitize.min.js',
'lib/angular-mocks.js',
'lib/jasmine-2.4.1/jasmine.js',
'lib/jasmine-2.4.1/jasmine-html.js',
'lib/jasmine-2.4.1/boot.js',
'../../js/app.js',
'spec/spec.js'
]
I've also had problems using minified and unminified versions of Angular modules in the same application. For instance, if you want to use minified versions of Angular, then make sure all of its submodules are minified too. I would say the same for any JavaScript dependency. Keep it consistent.
Upvotes: 1