HTML and CSS Reference
In-Depth Information
Still no luck. To make matters worse, adding that line actually failed the previous
test as well, because it didn't set a view. We can fix that by checking that the view
is set before asking it for elements, as Listing 15.25 does.
Listing 15.25 Checking that this.view is available
function handleSubmit(event) {
event.preventDefault();
if (this.view) {
var input = this.view.getElementsByTagName("input")[0];
this.model.currentUser = input.value;
}
}
That gets the previous test back to green, but the current test still fails. It turns
out that setView doesn't actually, well, set the view. Listing 15.26 fixes setView .
Listing 15.26 Storing a reference to the view
function setView(element) {
/* ... */
this.view = element;
}
And with that, all tests pass. We can now tend to the test case, which currently
duplicates some effort. Both of the tests create a stubbed event object, which can
and should be elevated to setUp . Listing 15.27 shows the updated setUp .
Listing 15.27 Stubbing event in setUp
function userFormControllerSetUp() {
/* ... */
this.event = { preventDefault: stubFn() };
}
15.2.2.4 Notifying Observers of the User
Once the user has been set, the controller should notify any observers. Listing 15.28
tests this by observing the event, handling the event and asserting that the observer
was called.
 
Search WWH ::




Custom Search