samedi 21 février 2015

Unknown provider in Karma test

I have the following provider:



(function (angular) {
angular.module('app')
.provider('$_Config', ConfigProvider);

function ConfigProvider() {
.... //routes definition
}
ConfigProvider.prototype.$get = function () {
return this;
};

ConfigProvider.prototype.getRoutes = function() {...}

//other prototype functions

})(angular);


In app.js I am using it like this:



app.config(function ($routeProvider, $_ConfigProvider) {
var routes = $_ConfigProvider.getRoutes();
routes.forEach(function(route) {
$routeProvider
.when(route.route, {
.....
})

}


Every thing work fine till it gets to testing. Here is my test:



describe('Provider: $_ConfigProvider', function () {

// load the providers module
beforeEach(module('app'));

// instantiate provider
var $_ConfigProvider;
beforeEach(inject(function (_$_Config_) {
$_ConfigProvider = _$_Config_;
}));


it('Should verify getRoutes function', function () {
var routes = $_ConfigProvider.getRoutes();
expect(Object.prototype.toString.call(routes) === '[object Array]').toBe(true);
});
});


When running the test I am getting the following error:



Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:unpr] Unknown provider: $_ConfigProvider


Note: The $_ConfigProvider is injected correctly during run-time.


Aucun commentaire:

Enregistrer un commentaire