HTML and CSS Reference
In-Depth Information
Listing 13.61 Accepting response data in complete
var fakeXMLHttpRequest = {
/* ... */
complete: function (status, responseText) {
this.status = status || 200;
this.responseText = responseText;
this.readyStateChange(4);
}
}
Listing 13.62 shows the test, which uses the updated complete method.
Listing 13.62 Expecting client to dispatch data
TestCase("CometClientConnectTest", {
setUp: function () {
/* ... */
this.ajaxCreate = ajax.create;
this.xhr = Object.create(fakeXMLHttpRequest);
ajax.create = stubFn(this.xhr);
},
tearDown: function () {
/* ... */
ajax.create = this.ajaxCreate;
},
/* ... */
"test should dispatch data from request": function () {
var data = { topic: [{ id: "1234" }],
otherTopic: [{ name: "Me" }] };
this.client.url = "/my/url";
this.client.dispatch = stubFn();
this.client.connect();
this.xhr.complete(200, JSON.stringify(data));
assert(this.client.dispatch.called);
assertEquals(data, this.client.dispatch.args[0]);
}
});
 
Search WWH ::




Custom Search