Current software versions for AngularJS and Jasmine:
AngularJS v1.2.26
Jasmine v2.2.0
I am facing an issue with a spyOn
. When attempting to change or remove its behavior, I encounter the following error message:
Error: getUpdate has already been spied upon
var data1 = 'foo';
var data2 = 'bar';
describe("a spec with a spy", function(){
beforeEach(module('app'));
var $q;
beforeEach(inject(function(_updateService_, _$q_){
updateService = _updateService_;
//Spy on the results of the getUpdate()
$q = _$q_;
var deferred = $q.defer();
deferred.resolve( data1 );
spyOn(updateService, 'getUpdate').and.returnValue(deferred.promise);
}));
describe('attempting to use a different spy here', function() {
it('should return a different value', function() {
var deferred = $q.defer();
deferred.resolve( data2 );
spyOn(updateService, 'getUpdate'); //ERROR OCCURS HERE
updateService.getUpdate.and.returnValue(deferred.promise);
...
});
});
...
If I remove the second spyOn statement, the test does not function properly.
What is the correct approach to resolve this issue?