Skip to Main Content
Mastering React Test-Driven Development - Second Edition
book

Mastering React Test-Driven Development - Second Edition

by Daniel Irvine
September 2022
Intermediate to advanced content levelIntermediate to advanced
564 pages
9h 56m
English
Packt Publishing
Content preview from Mastering React Test-Driven Development - Second Edition

6

Exploring Test Doubles

In this chapter, we’ll look at the most involved piece of the TDD puzzle: test doubles.

Jest has a set of convenience functions for test doubles, such as jest.spyOn and jest.fn. Unfortunately, using test doubles well is a bit of a dark art. If you don’t know what you’re doing, you can end up with complicated, brittle tests. Maybe this is why Jest doesn’t promote them as a first-class feature of its framework.

Don’t be turned off: test doubles are a highly effective and versatile tool. The trick is to restrict your usage to a small set of well-defined patterns, which you’ll learn about in the next few chapters.

In this chapter, we will build our own set of hand-crafted test double functions. They work pretty much just ...

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.
Start your free trial

You might also like

Full-Stack Web Development with GraphQL and React - Second Edition

Full-Stack Web Development with GraphQL and React - Second Edition

Sebastian Grebe

Publisher Resources

ISBN: 9781803247120Supplemental Content