Lets say we define a module 'A' with dependencies 'B' and 'C':
angular.module('A', ['B', 'C']).service('ServiceA', function(ServiceB) {
var val= ServiceB.getVal();
// do whatever A does
});
Now when I'm unit testing ServiceA in Jasmine, I want to mock out ServiceB.
I can do it such:
beforeEach(function() {
angular.module('B', []).service('ServiceB', function() {
this.getVal= function() {
return 1; // My mock value
};
});
);
// do my tests on ServiceA
This works fine, my mocked ServiceB gets injected into ServiceA. The
problem is that it happens globally, not just in this unit test. So every
subsequent unit test gets this mocked version of ServiceB, even the unit
test that is intended to test ServiceB.
Is there anyway to save the value of ServiceB before I mock it and then
restore it in a afterEach after the unit test is finished?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.