Modularize to Facilitate Testing
The complex getPrice in the spike turned out to be only a few lines of code in stockfetch.js, but a significant part of implementation that was in the spike is not done yet. Letâs continue to modularize, making each piece of code cohesive, narrow, and focused on a single responsibility.
Design the processResponse and processError Functions
Letâs turn our attention to the two new functions called from within getPrice. We can think through the tests for these functions now a lot better than when we focused on getPrice. Letâs add a few more tests for these functions:
- â¦
- â getPrice calls get on http with valid URL
- â getPrice calls get with a response handler as argument
- â getPrice registers handler for failure ...
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.