HTML and CSS Reference
In-Depth Information
this.controller.observe("user", observer);
this.controller.handleSubmit(this.event);
assertFalse(observer.called);
}
Passing this test requires a check on the value of the input field, as seen in
Listing 15.36.
Listing 15.36 Disallowing empty usernames
function handleSubmit(event) {
event.preventDefault();
if (this.view) {
var input = this.view.getElementsByTagName("input")[0];
var userName = input.value;
if (!userName) {
return;
}
/* ... */
}
}
The method also should not remove the “js-chat” class name if the username
was empty. The method clearly could benefit from notifying the user of the error as
well. As an exercise, I encourage you to add tests for and implement these additional
cases.
15.2.3 Feature Tests
With that, the user form controller is complete enough to provide the happy path.
It clearly could do with more resilient error handling and I strongly encourage you
to pick up doing so as exercises. One final touch we will add to the controller before
moving on is a set of feature tests to decide if the controller can be supported.
To add proper feature tests we need the actual event implementation as a
dependency, because the controller will require its existence at define time. Save
the addEventHandler implementation from Chapter 10, Feature Detection, in
lib/event.js . Listing 15.37 shows the controller including feature tests.
 
Search WWH ::




Custom Search