Predict Spy Call Arguments
Predict Output Medium
Question
What is the value of firstCallArgs?
Code
const spy = jest.spyOn(Math, 'max');
Math.max(3, 7);
const firstCallArgs = spy.mock.calls[0];
Hint
The first call passes 3 and 7.
Explanation
firstCallArgs is [3, 7]. jest.spyOn(Math, 'max') wraps Math.max and records all calls. The first call Math.max(3, 7) is stored in spy.mock.calls[0] as the array [3, 7]. You can use this to verify what arguments a function was called with.
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.