Creating Mock Functions In Jest
| Topic | Source |
|---|---|
| ๐งฉ 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' });