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);
}
}
If you only need to fake ajax success response, you can always fake it (see this question):
var fakeResponse;
$.ajax = function( options ) {
options.success( fakeResponse );
}
You only need to set the fakeResponse before having an object call $.ajax and it will call the object's success
function.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments