HTML and CSS Reference
In-Depth Information
requestComplete(transport, options);
transport.onreadystatechange = tddjs.noop;
/* ... */
Adding these two lines makes the tests pass again. Re-running the massive re-
quest integration test in Internet Explorer confirms that the memory leak is now
12.5.4 Local Requests
The last issue with the current implementation is that it is unable to make local
requests. Doing so results in no errors, yet “nothing happens.” The reason for this
is that the local file system has no concept of HTTP status codes, so the status code
is 0 when readyState is 4. Currently our implementation only accepts status
code 200, which is insufficient in any case. We will add support for local requests
by checking if the script is running locally and that the status code is not set, as the
test in Listing 12.44 shows.
Listing 12.44 Making sure the success handler is called for local requests
"test should call success handler for local requests":
function () {
this.xhr.readyState = 4;
this.xhr.status = 0;
var success = stubFn();
tddjs.isLocal = stubFn(true);
ajax.get("file.html", { success: success });
The test assumes a helper method tddjs.isLocal to check if the script is
running locally. Because we are stubbing it, a reference to it is saved in the setUp ,
allowing it to be restored in tearDown as we did before.
Search WWH ::

Custom Search