October 2016
Intermediate to advanced
364 pages
9h 8m
English
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 ...
Read now
Unlock full access