Design Service Interaction

The details of interaction with the back end—the GET, POST, and DELETE requests—will be put away in a separate service object. The controller’s getTasks function need not worry about them. It only has to make a call to the service and pass one callback for success and another for the error situation. These callbacks will be responsible for appropriately updating the models in the controllers.

From the design point of view, this approach makes the code modular and keeps the concerns apart in the code. From the testing point of view we don’t want the controller to interact with the real service for two reasons. One, we haven’t written the service yet. Two, interacting with the real service would make the test brittle ...

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.