Evolve Code in Small Steps

The first client-side feature we’ll implement will list all tasks when the page opens in a browser. For this we need a getTasks function. We listed three test in our test list for this function, but let’s analyze before starting to code.

getTasks should request tasks from the service, but it’s not the only function that will call the service. To keep the code DRY and cohesive, and to make testing easier, we’d want to delegate the task of calling the service to a separate function, say callService. getTasks would then invoke callService and register a callback, say updateTasks. The latter function would take on the responsibility to update a message DOM element if there was an error. Otherwise, it would update a

Get Test-Driving JavaScript Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.