Test Double Types
Question
What are the types of test doubles?
Hint
Test doubles replace real objects in tests.
Explanation
Test doubles are objects that replace real dependencies in tests: 1) Dummy — passed but never used (filler for parameters). 2) Stub — returns canned responses, ignores calls. 3) Spy — records calls, may delegate to real object. 4) Mock — pre-programmed with expectations, verifies calls. 5) Fake — simplified working implementation (in-memory database). The terms are often used loosely. In Jest, jest.fn() can serve as stub, spy, or mock depending on configuration. Understanding the distinction helps choose the right tool: stubs for controlling inputs, spies for verifying interactions, fakes for realistic behavior without external dependencies.
Related Resources
Related Lessons
- Stubs & Spies
Learn stubs.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.