Test-Drive the Service
The service class needs to provide a get function. This function will talk to the back end, fetch the data, extract the JSON response, and return an Observable to the caller. Let’s design this function, test first.
As the first step, let’s list the tests we need to implement the get function. Here again you can learn from the service you created during the spiking exercise.
- get should make GET request to /tasks
- extractData should return result from json()
- extractData should throw exception for invalid status
- returnError should return the error Observable
The first test is going to be an interaction test. The methods of HTTP return Rx.Observable. We will be calling the map and catch functions on the returned Observable. Since ...
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.