Spy vs Stub
Multiple Choice Medium
Question
What is the key difference between a spy and a stub?
Hint
One watches, the other replaces.
Explanation
A spy wraps a real function and records how it was called (arguments, return value, call count) while still allowing the original to run. A stub replaces a function entirely and returns preset values without executing the original. Spies are for verification; stubs are for controlling behavior.
Related Resources
Related Lessons
- Stubs and Spies
Understanding test doubles.
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.