Reputation: 495
I'm testing service A, but service A depends on service B. (eg service B is injected into service A) and service B depends on service C (eg service C is injected into service B).
I have tried mocking service B in service A
describe('Testing ServiceA', function () {
var serviceA, serviceBMock;
beforeEach(function () {
serviceBMock= {
get: function () {
return 'mockReturnValue';
}
};
angular.module('serviceAMocks', [])
.value('ServiceB', serviceBMock);
});
beforeEach(module('serviceAMocks'));
beforeEach(inject(function (_ServiceA_){
serviceA=_ServiceA_;
});
it('Gets', function () {
});
}
I get error:
Error: [$injector:unpr] Unknown provider: serviceC Provider <- ServiceC <- ServiceB<- ServiceA
if i remove it block no error if i place it block i get service C dependecy error.
Any help will be appreciated.
Upvotes: 0
Views: 536
Reputation: 18193
You can use code like this to make Angular inject your mocked service (Service B) into Service A:
beforeEach(module(function($provide) {
var serviceBMock= {
get: function () {
return 'mockReturnValue';
}
};
$provide.constant('serviceB', serviceBMock);
}));
Upvotes: 1