HTML and CSS Reference
In-Depth Information
Listing 15.42 Expecting messageListController to be an object
(function () {
var listController = tddjs.chat.messageListController;
TestCase("MessageListControllerTest", {
"test should be object": function () {
assertObject(listController);
}
});
}());
To pass the test, create lib/message _ list _ controller.js and save it
with the contents of Listing 15.43.
Listing 15.43 Defining messageListController
(function () {
var chat = tddjs.namespace("chat");
chat.messageListController = {};
}());
Next, we expect the controller to have a setModel method, as seen in Listing
15.44.
Listing 15.44 Expecting setModel to be a function
"test should have setModel method": function () {
assertFunction(listController.setModel);
}
Listing 15.45 adds an empty method.
Listing 15.45 Adding an empty setModel
function setModel(model) {}
chat.messageListController = {
setModel: setModel
};
15.4.1.2 Subscribing to Messages
setModel needs to observe the model's “message” channel. Remember, in pro-
duction, the model object will be a cometClient that streams messages from the
server. Listing 15.46 expects observe to be called.
 
Search WWH ::




Custom Search