HTML and CSS Reference
In-Depth Information
assertSame(this.controller, stub.thisValue);
I jumped the gun slightly on this one, immediately recognizing that a setUp was
required to avoid duplicating the test setup code. The test should look eerily familiar
because it basically mimics the test we wrote to verify that userFormController
observed the submit event with a bound handleSubmit method.
Listing 15.49 adds the correct handler to model.observe . What are your
expectations as to the result of running the tests?
Listing 15.49 Observing the “message” channel with a bound method
function setModel(model) {
model.observe("message", this.addMessage.bind(this));
If you expected the test to pass, but the previous test to fail, then you're abso-
lutely right. As before, we need to add the method we're binding to the controller,
to keep tests that aren't stubbing it from failing. Listing 15.50 adds the method.
Listing 15.50 Adding an empty addMessage
/* ... */
function addMessage(message) {}
chat.messageListController = {
setModel: setModel,
addMessage: addMessage
Before we can move on to test the addMessage method, we need to add a
view, because addMessage 's main task is to build DOM elements to inject into
it. As before, we're turning a blind eye to everything but the happy path. What
happens if someone calls setModel without an object? Or with an object that
does not support observe ? Write a few tests, and update the implementation as
you find necessary.
15.4.2 Setting the View
With the experience we gained while developing the user form controller, we will
use DOM elements in place of fake objects right from the start while developing
setView for the list controller. Listing 15.51 verifies that the method adds the
“js-chat” class to the view element.
Search WWH ::

Custom Search