HTML and CSS Reference
In-Depth Information
Implementing this is a simple matter of adding another line like the one that
passed headers, as seen in Listing 13.25.
Listing 13.25 Passing the success callback
ajax.request(this.url, {
/* ... */
headers: poller.headers,
success: poller.success
In order to check the failure callback the same way, we need to extend the
fake XMLHttpRequest object. Specifically, we now need to simulate completing
a request that failed in addition to the already implemented successful request. To
do this we can make complete accept an optional HTTP status code argument,
as Listing 13.26 shows.
Listing 13.26 Completing requests with any status
complete: function (status) {
this.status = status || 200;
Keeping 200 as the default status allows us to make this change without updating
or breaking any of the other tests. Now we can write a similar test and implemen-
tation to require the failure callback to be passed. The test is listed in Listing 13.27
and implementation in Listing 13.28
Listing 13.27 Expecting the failure callback to be passed
"test should pass failure callback": function () {
this.poller.failure = stubFn();
Search WWH ::

Custom Search