© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
D. IrvineBuild Your Own Test Frameworkhttps://doi.org/10.1007/978-1-4842-9247-1_16

16. Test Doubles

Daniel Irvine1  
(1)
London, UK
 

A test double is a special type of function (or object) that replaces a dependency of the structure under test with a “blank” version, which avoids doing any of the real work of the dependency.

In this chapter we’ll look at the common scenario of using test doubles to replace the global.fetch function that makes HTTP requests.

You’ll learn
  • The different types of test double

  • How to implement a spy function and its matcher

By the end of the chapter, you’ll be confident with the use of test doubles.

How Are Test Doubles Useful?

Usually these ...

Get Build Your Own Test Framework: A Practical Guide to Writing Better Automated Tests 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.