HTML and CSS Reference
In-Depth Information
Listing 15.72 Adding an empty function
function handleSubmit(event) {}
chat.messageFormController =
chat.messageFormController.handleSubmit = handleSubmit;
With the method in place we can start testing for its behavior. Listing 15.73
shows a test that expects it to publish a message event on the model.
Listing 15.73 Expecting the controller to publish a message event
TestCase("FormControllerHandleSubmitTest", {
"test should publish message": function () {
var controller = Object.create(messageController);
var model = { notify: stubFn() };
assertEquals("message", model.notify.args[0]);
Listing 15.74 adds the method call to pass the test.
Listing 15.74 Calling publish
function handleSubmit(event) {
this.model.notify("message", {});
Tests are all passing. Next up, Listing 15.75 expects the published object to
include the currentUser as its user property.
Listing 15.75 Expecting currentUser as user
TestCase("FormControllerHandleSubmitTest", {
setUp: function () {
this.controller = Object.create(messageController);
this.model = { notify: stubFn() };
Search WWH ::

Custom Search