Test Interactions

We’ve tested and implemented the createURL and setLocation functions. That leaves three more functions to be tested and implemented from our modular design diagram. Let’s pick the locate function next as that will help us explore a technique we’ve not seen so far in this book—testing interactions.

The tests we’ve written so far are all empirical tests. You call a method and assert that it returned a desired result—synchronously or asynchronously. When working with dependencies, often it’s hard to predict the results. For example, if code depends on a service that returns the current temperature in Chicago, it’s hard to write an empirical test for that code. Interaction tests are better for code with dependencies.

A test for ...

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.