HTML and CSS Reference
In-Depth Information
Listing 12.28 Verifying that the ready state handler is assigned
"test should add onreadystatechange handler": function () {
ajax.get("/url");
assertFunction(this.xhr.onreadystatechange);
}
As expected, the test fails because xhr.onreadystatechange is unde-
fined. We can assign an empty function for now, as Listing 12.29 shows.
Listing 12.29 Assigning an empty onreadystatechange handler
function get(url) {
/* ... */
transport.onreadystatechange = function () {};
}
To kick off the request, we need to call the send method. This means that we
need to add a stubbed send method to fakeXMLHttpRequest and assert that
it was called. Listing 12.30 shows the updated object.
Listing 12.30 Adding a stub send method
var fakeXMLHttpRequest = {
open: stubFn(),
send: stubFn()
};
Listing 12.31 expects the send method to be called by ajax.get .
Listing 12.31 Expecting get to call send
TestCase("GetRequestTest", {
/* ... */
"test should call send": function () {
ajax.get("/url");
assert(xhr.send.called);
}
});
 
Search WWH ::




Custom Search