Predict Mock Return Value
Predict Output Medium
Question
What does this test print to the console?
Code
const mockFn = jest.fn().mockReturnValue(42);
console.log(mockFn());
Hint
mockReturnValue sets what the mock returns.
Explanation
The code prints 42. jest.fn() creates a mock function, and .mockReturnValue(42) configures it to always return 42 when called. So mockFn() returns 42, which is logged to the console.
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.