HTML and CSS Reference
In-Depth Information
15
TDD and DOM
Manipulation:
The Chat Client
D eveloping client-side JavaScript includes a fair amount of DOM manipulation.
In this chapter we will use test-driven development to implement a client for the
chat backend we developed in Chapter 14, Server-Side JavaScript with Node.js. By
doing so we will see how to apply the techniques we have learned so far to test DOM
manipulation and event handling.
The DOM is an API just like any other, which means that testing it should be
fairly straightforward so long as we adhere to the single responsibility principle and
keep components loosely coupled. The DOM does potentially present a challenge
in that it consists entirely of host objects, but as we will see, we can work around
the potential problems.
15.1 Planning the Client
The task at hand is building a simple chat GUI. The resulting application will have
two views: when the user enters the application she will be presented with a form in
which to enter the desired username. Submitting the form will remove it and display
a list of messages and a form to enter new ones in its place. As usual, we will keep
the scope at a minimum to get through the entire exercise, so for example, there
will be no cookie management to remember the user. Throughout the chapter ideas
on how to add more features to the client will be suggested as exercises.
389
 
 
 
Search WWH ::




Custom Search