Use Sinon to Reduce Noise
The key to writing an automated test for locate was replacing the dependency with a test double. In the test in the file test/locate-test.js, we handmade the mock and manually replaced and restored the getCurrentPosition function. This approach can soon turn into drudgery and make tests verbose and error prone.
A good test doubles library can alleviate the pain significantly. Sinon is one such tool that can be used with any JavaScript testing tool. It’s concise, fluent, and powerful—you’ll see the tool shine in later chapters when we automate tests for Node.js, Express, and jQuery. Let’s use Sinon test doubles instead of the handmade ones.
Later ...
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.