Summary
In this chapter, we explored test doubles and how they are used to verify interactions with collaborating objects. We looked in detail at spies and stubs, the two main types of doubles you'll use. As we went through, we used a couple of additional testing techniques: we built a Jest matcher, and we built a side-by-side implementation that helped us keep most of our existing tests green as we reworked our component.
Then we removed our hand-rolled code in favor of Jest's own built-in functionality, which helped to dry up our tests.
We also extracted a bunch of helper code into modules that made our tests more readable, because they are shorter and clearer about their intent.
In the next chapter, we'll tie each of our components together ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access