I have the following provider:
(function (angular) { angular.module('app') .provider('$_Config', ConfigProvider); function ConfigProvider() { ....
In app.js, I use it as follows:
app.config(function ($routeProvider, $_ConfigProvider) { var routes = $_ConfigProvider.getRoutes(); routes.forEach(function(route) { $routeProvider .when(route.route, { ..... }) }
Everything works fine until it comes 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 starting the test, I get the following error:
Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:unpr] Unknown provider: $_ConfigProvider
Note: $_ConfigProvider is entered correctly at run time.
source share