Recently, I've taken over an Angular project that utilizes npm, grunt, bower, karma, and jasmin. One of my tasks is to set up tests for the project using karma and jasmin. Although karma has already been configured in the project, it has never been used. When attempting to run 'grunt test', I encountered injection errors with all of the services, similar to the following:
Error: [$injector:unpr] Unknown provider: excelparserserviceProvider <- excelparserservice http://errors.angularjs.org/1.2.6/$injector/unprp0=excelparserserviceProvider%20%3C-%20excelparserservice
The karma.conf.js file already exists within the project, and I have made no changes to it other than adding some libraries used by the project to the list under Files: [].
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/bower_components/angular-resource/angular-resource.js',
......
<i>(List of included files continues...)</i>
],
.....
I noticed the paths,
'app/scripts/*.js' leads to app.js and a config.js
'app/scripts/**/*.js' includes all services controllers and directives
'test/mock/**/*.js' does not exist
'test/spec/**/*.js' contains all the test files
There are corresponding test files for every part of the application which were supposedly auto-generated. However, it's strange if they contain the error. The one related to the excpelparserservice injection error is...
'use strict';
describe('Service: excelparserservice', function () {
// load the service's module
beforeEach(module('batchUploadApp'));
.....
});
The declaration of the service appears as follows.
'use strict';
angular.module('batchUploadApp')
.service('ExcelParserService',
function ExcelParserService($q, ExcelvalidationService, GeoLocationService) {
In general, the application works fine. I hope this explanation is helpful :) Thank you.