TAILIEUCHUNG - Test Driven JavaScript Development- P22

Test Driven JavaScript Development- P22:This book is about programming JavaScript for the real world, using the techniques and workflow suggested by Test-Driven Development. It is about gaining confidence in your code through test coverage, and gaining the ability to fearlessly refactor and organically evolve your code base. It is about writing modular and testable code. It is about writing JavaScript that works in a wide variety of environments and that doesn’t get in your user’s way. | The Message List 413 Listing Expecting setModel to observe the message channel TestCase MessageListControllerSetModelTest test should observe model s message channel function var controller listController var model observe stubFn model assert assertEquals message 0 assertFunction 1 The test fails and Listing helps passing it by making the call to observe. Listing Calling observe function setModel model message function Next we ll expect the handler to be a bound addMessage method much like we did with the DOM event handler in the user form controller. Listing shows the test. Listing Expecting a bound addMessage as message handler TestCase MessageListControllerSetModelTest setUp function listController observe stubFn . test should observe with bound addMessage function var stub stubFn 1 assert Please purchase PDF Split-Merge on to remove this watermark. From the Library of 414 TDD and DOM Manipulation The Chat Client assertSame 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 adds the correct handler to . What are your expectations as to the result of running the tests Listing Observing the message channel with a bound method function setModel model message this If you expected the test to pass but the previous test to fail then you re absolutely right. As before we need to add the method we re binding to the .