HTML and CSS Reference
In-Depth Information
Next up, Listing 13.32 makes sure the url property is set on the poller. In
order to make this assertion we need a reference to the poller object, so the method
will need to return it.
Listing 13.32 Expecting the url property to be set
"test should set url property on poller object":
function () {
var poller = ajax.poll("/url");
assertSame("/url", poller.url);
}
Implementing this test requires two additional lines, as in Listing 13.33.
Listing 13.33 Setting the URL
function poll(url, options) {
var poller = Object.create(ajax.poller);
poller.url = url;
poller.start();
return poller;
}
The remaining tests will simply check that the headers, callbacks, and interval
are set properly on the poller. Doing so closely resembles what we just did with the
underlying poller interface, so I'll leave writing the tests as an exercise.
Listing 13.34 shows the final version of ajax.poll .
Listing 13.34 Final version of ajax.poll
function poll(url, options) {
var poller = Object.create(ajax.poller);
poller.url = url;
options = options || {};
poller.headers = options.headers;
poller.success = options.success;
poller.failure = options.failure;
poller.complete = options.complete;
poller.interval = options.interval;
poller.start();
return poller;
}
ajax.poll = poll;
 
Search WWH ::




Custom Search