Creating Mock Functions In Jest

TopicSource
๐Ÿงฉ React[React Testing Library and Jest: The Complete Guide

const mock = jest.fn(); // create a mock function that doesn't do anything. You can also handle stuff in here (e.g. event.preventDefault())

render(<UserForm onUserAdd={ mock }) />);
...

expect(mock).toHaveBeenCalled();
expect(mock).toHaveBeenCalledWith({ name: 'jane', email: 'jane@jane.com' });

  1. Set up Jest environment