Employ Test Doubles

Test doubles are objects that replace real dependencies to enable automated testing. Test doubles are the automated testing equivalent of movie stunt people—they take the place of the original since having the real one is expensive or impractical. You will learn the role of test doubles using the setLocation function as an example.

The setLocation function is a simple one. It takes a URL for Google Maps and sets that into the location property of the window object, thus instructing the browser to display the map with the user’s current location. It’s easy to write but may appear hard to test.

We don’t want to load an HTML page in a browser, then call the setLocation function to see if the browser navigates to the ...

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.