Skip to content

Instantly share code, notes, and snippets.

@MrJadaml
Last active October 26, 2022 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrJadaml/ee67849445a26d19a30af8e103963258 to your computer and use it in GitHub Desktop.
Save MrJadaml/ee67849445a26d19a30af8e103963258 to your computer and use it in GitHub Desktop.
const Modal = ({ children, onClose }) => (
<div role="presentation">
<OutsideClickHandler onOutsideClick={onClose}>
<div> modal stuff... </div>
</OutsideClickHandler>
</div>
)
it('should close modal when clicked outside', () => {
const mockHandleClose = jest.fn()
render(<Modal {...props} onClose={mockHandleClose} />)
fireEvent.click(document)
// userEvent.click(document.body) -- Tried this as well with no luck
expect(mockHandleClose).toBeCalled()
})
// Test output:
// expect(jest.fn()).toBeCalled()
// Expected number of calls: >= 1
// Received number of calls: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment