HTML and CSS Reference
In-Depth Information
Having discovered a deficiency in the wild, our immediate reaction as TDD-ers
is to capture it in a test. Capturing the bug by verifying that our code handles the
exception is all fine, but does not help Firefox
= 3.0.x get the request through. A
better solution is to assert that send is called with an argument. Seeing that GET
requests never have a request body, we simply pass it null . The test goes in the
GetRequestTest test case and can be seen in Listing 12.40.
Listing 12.40 Asserting that send is called with an argument
"test should pass null as argument to send": function () {
The test fails, so Listing 12.41 updates ajax.get to pass null directly to
send .
Listing 12.41 Passing null to send
function get(url, options) {
/* ... */
Our tests are back to a healthy green, and now the integration test runs
smoothly on Firefox as well. In fact, it now runs on all Firefox versions, includ-
ing back when it was called Firebird (0.7). Other browsers cope fine too, for in-
stance Internet Explorer versions 5 and up run the test successfully. The code
was tested on a wide variety of new and old browsers. All of them either com-
pleted the test successfully or gracefully printed that “Browser does not support
tddjs.ajax.get .”
12.5.3 Subtle Trouble Ahead
There is one more problem with the code as is, if not as obvious as the pre-
vious obstacle. The XMLHttpRequest object and the function assigned to its
onreadystatechange property creates a circular reference that causes mem-
ory leaks in Internet Explorer. To see this in effect, create another test page like
the previous one, only make 1,000 requests. Watch Internet Explorer's memory
usage in the Windows task manager. It should skyrocket, and what's worse is that
Search WWH ::

Custom Search