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- ✓Correct answer:
expect(onSave).toHaveBeenCalledWith({ name: "Ann" }) - 2
expect(onSave()).toBe({ name: "Ann" }) - 3
expect(onSave.called).toBe(true)
Explanation
There is also toHaveBeenCalledTimes(n) and toHaveBeenLastCalledWith(...).