HTML and CSS Reference
In-Depth Information
Listing 15.46 Expecting setModel to observe the “message” channel
TestCase("MessageListControllerSetModelTest", {
"test should observe model's message channel":
function () {
var controller = Object.create(listController);
var model = { observe: stubFn() };
controller.setModel(model);
assert(model.observe.called);
assertEquals("message", model.observe.args[0]);
assertFunction(model.observe.args[1]);
}
});
The test fails, and Listing 15.47 helps passing it by making the call to observe .
Listing 15.47 Calling observe
function setModel(model) {
model.observe("message", function () {});
}
Next, we'll expect the handler to be a bound addMessage method, much
like we did with the DOM event handler in the user form controller. Listing 15.48
shows the test.
Listing 15.48 Expecting a bound addMessage as “message” handler
TestCase("MessageListControllerSetModelTest", {
setUp: function () {
this.controller = Object.create(listController);
this.model = { observe: stubFn() };
},
/* ... */
"test should observe with bound addMessage": function () {
var stub = this.controller.addMessage = stubFn();
this.controller.setModel(this.model);
this.model.observe.args[1]();
assert(stub.called);
 
Search WWH ::




Custom Search