How do we clear the spy in a jasmine test suite programmatically? Thanks.
beforeEach(function() {
spyOn($, \"ajax\").andCallFake(function(params){
})
})
This worked for me in Jasmine 2.5 to allow re-setting of mock ajax.
function spyOnAjax(mockResult) {
// must set to true to allow multiple calls to spyOn:
jasmine.getEnv().allowRespy(true);
spyOn($, 'ajax').and.callFake(function () {
var deferred = $.Deferred();
deferred.resolve(mockResult);
return deferred.promise();
});
}
Then you can call it multiple times without error. spyOnAjax(mock1); spyOnAjax(mock2);