HTML and CSS Reference
In-Depth Information
Listing 15.69 Inheriting from formController
chat.messageFormController =
Object.create(chat.formController);
15.5.3 Publishing Messages
When the user submits the form, the controller should publish a message to the
model object. To test this we can stub the model's notify method, call handle-
Submit , and expect the stub to be called. Unfortunately, the controller does not
yet have a setModel method. To fix this, we will move the method from user-
FormController to formController . Listing 15.70 shows the updated form
controller.
Listing 15.70 Moving setModel
/* ... */
function setModel(model) {
this.model = model;
}
chat.formController = {
setView: setView,
setModel: setModel
};
Having copied it over, we can remove it from userFormController .To
verify that we didn't break anything, we simply run the tests, which should be all
green. To our infinite satisfaction, they are.
There is no setModel related test to write for messageFormController
that can be expected to fail, thus we won't do that. We're TDD-ing, we want
progress, and progress comes from failing tests.
A test that can push us forward is one that expects the controller to have a
handleSubmit method, which can be seen in Listing 15.71.
Listing 15.71 Expecting the controller to have a handleSubmit method
"test should have handleSubmit method": function () {
assertFunction(messageController.handleSubmit);
}
Listing 15.72 passes the test by adding an empty function.
 
Search WWH ::




Custom Search