Concept: When to Mock
Concept Check Medium
Question
When should you use a mock?
Hint
Mock to solve specific problems, not by default.
Explanation
You should mock when a dependency is slow (network calls), non-deterministic (current time, random), or external (third-party API, database). Mocking everything leads to tests that don't test real behavior. Not mocking at all leads to slow, brittle tests. The key is mocking judiciously — only when there's a real reason.
Related Resources
Related Lessons
- Mocking
Using mocks to isolate code.
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.