Skip to main content
Testing & QA Output Prediction Medium +20 XP

Mock Return Value

What does mockFn() return?

Testing & QARead-only
const mockFn = jest.fn().mockReturnValue(42);
console.log(mockFn());

What is the output?

Show answer and explanation

Answer: 42

mockReturnValue(42) configures the mock to return 42 whenever it's called.

Hint: mockReturnValue sets what the function returns.

What this challenge tests

Output Prediction in Testing & QA: jest, mocking.

Related challenges