HTML and CSS Reference
In-Depth Information
function () {
var request = forceStatusAndReadyState(this.xhr, 400, 4);
assert(request.complete);
},
"test should call complete handler for status 0":
function () {
var request = forceStatusAndReadyState(this.xhr, 0, 4);
assert(request.complete);
}
});
As expected, all three tests fail given that no complete callback is called
anywhere. Adding it in is straightforward, as Listing 13.13 illustrates.
Listing 13.13 Calling the complete callback
function requestComplete(options) {
var transport = options.transport;
if (isSuccess(transport)) {
if (typeof options.success == "function") {
options.success(transport);
}
} else {
if (typeof options.failure == "function") {
options.failure(transport);
}
}
if (typeof options.complete == "function") {
options.complete(transport);
}
}
When a request is completed, the poller should schedule another request.
Scheduling ahead of time is done with timers, typically setTimeout for a sin-
gle execution such as this. Because the new request will end up calling the same
callback that scheduled it, another one will be scheduled, and we have a continu-
ous polling scheme, even without setInterval . Before we can implement this
feature we need to understand how we can test timers.
 
Search WWH ::




Custom Search