© 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_17

17. Module Mocks

Daniel Irvine1  
(1)
London, UK
 
The last chapter discussed why test spies are useful, and it showed one way that we can inject the spy into our application codeby simply overriding the value:
global.fetch = spy(...);

It turns out that spies are pretty simple to use when they are replacing global functions or when we can pass in the spy as a constructor argument.

But one occasion that it’s difficult to do this is when dealing with named exports that the application code imports and loads. This is often the case with component frameworks like React.

In this chapter, ...

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.