Testing·Beginner·Conceptual·1 min read
What is the difference between jest.fn() and jest.spyOn()?
Short interview answer
jest.fn() creates a brand-new mock function with no prior implementation, while jest.spyOn() wraps an existing method on an object, by default still calling through to the real implementation unless configured otherwise.
Key takeaway
Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.