HTML and CSS Reference
In-Depth Information
Listing 13.20 Expecting the request interval to be configurable
TestCase("PollerTest", {
/* ... */
tearDown: function () {
ajax.create = this.ajaxCreate;
/* ... */
"test should configure request interval":
function () {
this.poller.interval = 350;
this.xhr.send = stubFn();
This test does a few things different from the previous two tests. First of all, we
add the call to Clock.reset in the tearDown method to avoid tests interfering
with each other. Second, this test first skips ahead 349ms, asserts that the new re-
quest was not issued, then leaps the last millisecond and expects the request to have
been made.
We usually try hard to keep each test focused on a single behavior, which is
why we rarely make an assertion, exercise the code more, and then make another
assertion the way this test does. Normally, I advise against it, but in this case both of
the asserts contribute to testing the same behavior—that the new request is issued
exactly 350ms after the first request finishes; no less and no more.
Implementing the test is a simple matter of using poller.interval if it is
a number, falling back to the default 1,000ms, as Listing 13.21 shows.
Listing 13.21 Configurable interval
function start() {
/* ... */
var interval = 1000;
Search WWH ::

Custom Search