I am currently working on setting up a basic unit test example. Everything is running smoothly with this app.js:
var whapp = angular.module('whapp', [])
.filter('reverse', [function(){
return function(string){
return string.split('').reverse().join('');
}
}]);
And this spec.js:
describe('Filters', function(){
beforeEach(module('whapp'));
describe('reverse', function(){
var reverse, rootScope;
beforeEach(inject(function($filter){
reverse = $filter('reverse', {});
}));
it('Should reverse a string', function(){
expect(reverse('rahil')).toBe('lihar');
});
});
});
Using this karma files configuration:
files: [
'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',
'node_modules/angular-mocks/angular-route/angular-route.js',
'node_modules/angular-mocks/angular-ui-router/release/angular-ui-router.js',
'app/js/*.js',
'tests/*.js'
]
The issue arises when I attempt to inject ngRoute into my module in app.js like this:
var whapp = angular.module('whapp', ['ngRoute'])
.filter('reverse', [function(){
return function(string){
return string.split('').reverse().join('');
}
}]);
At this point, I encounter the following error in karma [UPDATE: this error persists even if I don't load the angular-mocks.js library into karma as shown above]:
TypeError: undefined is not a constructor (evaluating 'reverse('rahil')') in tests/spec.js (line 9)
So... how can I correctly inject ngRoute into spec.js? I have tried various approaches, but none have been successful.