HTML and CSS Reference
In-Depth Information
Listing 15.51 Expecting setView to set the element's class
function messageListControllerSetUp() {
/*:DOC element = <dl></dl> */
this.controller = Object.create(listController);
this.model = { observe: stubFn() };
TestCase("MessageListControllerSetModelTest", {
setUp: messageListControllerSetUp,
/* ... */
TestCase("MessageListControllerSetViewTest", {
setUp: messageListControllerSetUp,
"test should set class to js-chat": function () {
assertClassName("js-chat", this.element);
We've danced the extract setup dance enough times now that hopefully the
above listing should not be too frightening. Even though parts of the TDD process
do become predictable after awhile, it's important to stick to the rhythm. No matter
how obvious some feature may seem, we should be extremely careful about adding it
until we can prove we really need it. Remember, You Ain't Gonna Need It. Keeping
to the rhythm ensures neither production code nor tests are any more complicated
than what they need to be.
The test fails because the setView method does not exist. Listing 15.52 adds
it and passes the test in one fell swoop.
Listing 15.52 Adding a compliant setView method
function setView(element) {
element.className = "js-chat";
chat.messageListController = {
setModel: setModel,
setView: setView,
addMessage: addMessage
Search WWH ::

Custom Search