I am getting this error: "Error: [$injector:unpr] Unknown provider: $provideProvider <- $provide". I been stuck for hours googling around. I have seen many examples where it is done this way and I am unsure of what to do.
"use strict";
describe('Controller: ProfileCtrl', function ($provide) {
//load the controller's module
var mockProfileFactory;
beforeEach(function() {
module('profileUpdate', function($provide) {
mockProfileFactory = {
get: function() {
id: 16
}
};
$provide.value('Profile', mockProfileFactory);
});
var ProfileCtrl;
var scope;
inject(function ($controller, $rootScope, $provide) {
scope = $rootScope.$new();
ProfileCtrl = $controller('ProfileCtrl', {
$scope: scope
});
});
});
it('should have 3 items', function() {
var things = scope.range(1,3,1);
expect(things).toBe(3);
});
});
You had a few bonus provides. In particular the one in the inject statement. You can't inject provide, it is only available to modules. Try my changes below.
"use strict";
// SEE no provide here
describe('Controller: ProfileCtrl', function () {
//load the controller's module
var mockProfileFactory;
beforeEach(function() {
module('profileUpdate', function($provide) {
mockProfileFactory = {
get: function() {
id: 16
}
};
$provide.value('Profile', mockProfileFactory);
});
var ProfileCtrl;
var scope;
// SEE and neither in the inject here
inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
ProfileCtrl = $controller('ProfileCtrl', {
$scope: scope
});
});
});
it('should have 3 items', function() {
var things = scope.range(1,3,1);
expect(things).toBe(3);
});
});
Have a read about the angularjs concept of providers, and also check your code against this guide:
http://nathanleclaire.com/blog/2013/12/13/how-to-unit-test-controllers-in-angularjs-without-setting-your-hair-on-fire/
$provide is a provider, you can only inject $provide in app.config method, not in controller method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With