diff --git a/docs/dom-testing-library/api-events.md b/docs/dom-testing-library/api-events.md index e9604591e..a6a6c57ab 100644 --- a/docs/dom-testing-library/api-events.md +++ b/docs/dom-testing-library/api-events.md @@ -130,3 +130,29 @@ fireEvent( }) ) ``` + +## Using Jest Function Mocks + +[Jest's Mock functions](https://jestjs.io/docs/en/mock-functions) can be used to test +that a callback passed to the function was called, or what it was called when the event +that **should** trigger the callback function does trigger the bound callback. + + + + + + +```jsx +import { render, screen } from '@testing-library/react' + +const Button = ({onClick, children}) => + +test('calls onClick prop when clicked', () => { + const handleClick = jest.fn() + render() + fireEvent.click(screen.getByText(/click me/i)) + expect(handleClick).toHaveBeenCalledTimes(1) +}) +``` + +