HTML and CSS Reference
In-Depth Information
lead to multiple simultaneous connections, which is not desired. A better solution
is to trigger a delayed request once the previous one finishes. This means that we
have to wrap the success and failure callbacks.
Rather than adding identical success and failure callbacks (save for which
user defined callback they delegate to), we are going to make a small addition to
tddjs.ajax.request ; the complete callback will be called when a request
is complete, regardless of success. Listing 13.12 shows the update needed in the
requestWithReadyStateAndStatus helper, as well as three new tests,
asserting that the complete callback is called for successful, failed, and local
requests.
Listing 13.12 Specifying the complete callback
function forceStatusAndReadyState(xhr, status, rs) {
var success = stubFn();
var failure = stubFn();
var complete = stubFn();
ajax.get("/url", {
success: success,
failure: failure,
complete: complete
});
xhr.complete(status, rs);
return {
success: success.called,
failure: failure.called,
complete: complete.called
};
}
TestCase("ReadyStateHandlerTest", {
/* ... */
"test should call complete handler for status 200":
function () {
var request = forceStatusAndReadyState(this.xhr, 200, 4);
assert(request.complete);
},
"test should call complete handler for status 400":
 
Search WWH ::




Custom Search