HTML and CSS Reference
In-Depth Information
Listing 15.67 Changing userFormController 's ancestry
chat.userFormController = tddjs.extend(
Object.create(chat.formController),
util.observable
);
Running the tests confirms that this change does not interfere with the exist-
ing behavior of the user form controller. Next up, we remove userFormCon-
troller 's own setView implementation. The expectation is that it should now
inherit this method from formController thus the tests should still pass. Run-
ning them confirms that they do.
Before the refactoring can be considered done, we should change the tests as
well. The tests we originally wrote for the user form controller's setView should
now be updated to test formController directly. To make sure the user form
controller still works, we can replace the original test case with a single test that veri-
fies that it inherits the setView method. Although keeping the original tests better
documents userFormController , duplicating them comes with a maintenance
cost. I'll leave fixing the test case as an exercise.
15.5.2.2 Setting messageFormController 's View
Having extracted the formController , we can add a test for messageForm-
Controller expecting it to inherit the setView method, as Listing 15.68 shows.
Listing 15.68 Expecting messageFormController to inherit setView
(function () {
var messageController = tddjs.chat.messageFormController;
var formController = tddjs.chat.formController;
TestCase("FormControllerTestCase", {
/* ... */
"test should inherit setView from formController":
function () {
assertSame(messageController.setView,
formController.setView);
}
});
}());
Passing the test is achieved by changing the definition of the controller, as seen
in Listing 15.69.
 
Search WWH ::




Custom Search