HTML and CSS Reference
In-Depth Information
assert(client.observers.notify.called);
assertEquals("someEvent", args[0]);
assertEquals({ id: 1234 }, args[1]);
}
The simple data object in this test conforms to the format we specified in the
introduction. To pass this test we need to loop the properties of the data object,
and then loop each topic's events and pass them to the observers, one by one. Listing
13.48 takes the job.
Listing 13.48 Dispatching data
function dispatch(data) {
var observers = this.observers;
tddjs.each(data, function (topic, events) {
for(vari=0,l=events.length; i < l; i++) {
observers.notify(topic, events[i]);
}
});
}
The test passes, but this method clearly makes a fair share of assumptions; thus,
it can easily break in lots of situations. We'll harden the implementation through a
series of small tests for discrepancies.
13.4.3.3 Improved Error Handling
Listing 13.49 asserts that it doesn't break if there are no observers .
Listing 13.49 What happens if there are no observers?
TestCase("CometClientDispatchTest", {
setUp: function () {
this.client = Object.create(ajax.cometClient);
},
/* ... */
"test should not throw if no observers": function () {
this.client.observers = null;
assertNoException(function () {
this.client.dispatch({ someEvent: [{}] });
}.bind(this));
},
 
Search WWH ::




Custom Search