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 ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.