I am writing some QUnit tests for a JavaScript that makes AJAX calls.
For isolation I overwrite $.ajax to write the parameter array of an AJAX call to a
After reading inspired by @Robusto and @Val, I found a method that works:
//Mock ajax function
$.ajax = function (param) {
_mockAjaxOptions = param;
//call success handler
param.complete("data", "textStatus", "jqXHR");
};
Instead of raising the event from any real $.ajax code or by triggering any events, I have my fake ajax object call the function (which is passed in as a parameter to $.ajax()) as part of my fake function.