Testing · Junior · Question 32 of 78

How do you check that a callback was called with specific arguments?

const onSave = vi.fn();
render(<Form onSave={onSave} />);
// ...user fills the form and submits

Explanation

There is also toHaveBeenCalledTimes(n) and toHaveBeenLastCalledWith(...).

Further reading

Problem with a question

Testing · Junior · question 32

Test yourself

Take the Testing · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz