HTML and CSS Reference
In-Depth Information
The key aspect of this chapter has been unit testing DOM manipulation, and
structuring the outermost application layer in a sensible way. As we've discussed
numerous times already, well factored software easily lends itself to unit testing, and
the GUI—the DOM—is no exception to this rule.
By employing the Model View Presenter/Passive View pattern, we were able
to identify reusable components in the view and implement the chat client in a
modular way, resulting in very loosely coupled modules that were easy to test in
isolation. Developing these components using TDD was straightforward because
each distinct unit had a well-defined responsibility. Dividing a hard problem into
several smaller problems is a lot more manageable than trying to solve it all in
one go.
An interesting aspect about a pattern such as Model View Presenter is that there
are numerous ways to apply it to the problem domain of client-side JavaScript. For
instance, in many cases a portion of the DOM will represent the model because
JavaScript widgets frequently manipulate the data already found on the page.
The chat client was the final test-driven example, and we have reached the end
of Part III, Real-World Test-Driven Development in JavaScript. In the final part of
the topic we'll draw some lessons from the past five chapters as we dive deeper into
stubbing and mocking, and finally identify some guidelines for writing good unit
tests.
Search WWH ::




Custom Search