HTML and CSS Reference
In-Depth Information
use the ajax.poller object we just built, which means that we can specify its
behavior mostly in terms of a stubbed implementation of it.
The first test will assert that an object inheriting from ajax.poller is created
using Object.create and that its start method is called, as Listing 13.30
Listing 13.30 Expecting the start method to be called
TestCase("PollTest", {
setUp: function () {
this.request = ajax.request;
this.create = Object.create;
ajax.request = stubFn();
tearDown: function () {
ajax.request = this.request;
Object.create = this.create;
"test should call start on poller object": function () {
var poller = { start: stubFn() };
Object.create = stubFn(poller);
This test case does the usual setup to stub and recover a few methods. By
now, this wasteful duplication should definitely be rubbing you the wrong way. As
mentioned in the previous chapter, we will have to live with it for now, as we will
introduce better stubbing tools in Chapter 16, Mocking and Stubbing.
Apart from the setup, the first test makes sure a new object is created and that
its start method is called, and the implementation can be seen in Listing 13.31.
Listing 13.31 Creating and starting a poller
function poll(url, options) {
var poller = Object.create(ajax.poller);
ajax.poll = poll;
Search WWH ::

Custom Search