I'm doing a very simple xhr mock example and need the ability to setup the return success (also in this specific example I can't use a library).
function fakeHttpRequest(json) {
$.ajaxSetup({
complete: function() {
this.success.call(this, json);
}
});
}
What I'm doing above works great except that if I call it 3 times, the last integration test I'm using this in returns 3 different times (instead of the 1 as I expected). Is it possible to invoke this and clear it or reset it between tests?
Update
Here is what I ended up with
function fakeHttpRequest(json) {
jQuery.ajax = function(opts) {
opts.success(json);
}
}