Reputation: 1961
Im writing tests with karma + jasmine. Look at this:
describe("users module", function(){
var scope, controller;
beforeEach(function () {
module('users');
});
it("should work", function(){
});
});
The above code is working and i get this output
PhantomJS 2.1.1 (Linux 0.0.0): Executed 1 of 1 SUCCESS (0.038 secs / 0.001 secs)
What i really need to do here is testing that module controllers. So i am adding:
describe("users module", function(){
var scope, controller;
beforeEach(function () {
module('users');
});
describe("Users list", function(){
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller('ctrl', {
'$scope': scope
});
}));
it("should work", function(){
});
});
});
When i add the second beforeEach
block i get an injection error. The error dump is huge, it starts like so:
Error: [$injector:modulerr] http://errors.angularjs.org/1.5.7/$injector/modulerr?p0=users
I've tried to dry the code as much as possible but even the following leads to the same error:
describe("users module", function(){
var scope, controller;
beforeEach(function () {
module('users');
});
describe("Users list", function(){
beforeEach(inject(function () {
}));
it("should work", function(){
});
});
});
What's wrong with my code?
==EDIT==
If i switch to non-minified angular version i get a readable error dump, which looks like as follows:
public/src/bower_components/angular/angular.js:4632:53
forEach@public/src/bower_components/angular/angular.js:321:24
loadModules@public/src/bower_components/angular/angular.js:4592:12
createInjector@public/src/bower_components/angular/angular.js:4514:30
workFn@public/src/bower_components/angular-mocks/angular-mocks.js:3067:60
loaded@http://localhost:9876/context.js:151:17
Upvotes: 0
Views: 497
Reputation: 1961
It turned out i misspelled a module dependency.
Lesson: if angular's saying it has troubles creating module users
, that's most probably true and you must investigate that error first.
Upvotes: 1