import React from 'react'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { Modal } from './Modal'; describe('Modal', () => { it('renders correctly', () => { render( {}}>Hello); expect(screen.getByText('Hello')).toBeVisible(); }); it('should only close when the modal wrapper is clicked', async () => { const onClose = jest.fn(); const onClickButton = jest.fn(); render( ); const modal = screen.getByTestId('modal'); const button = screen.getByTestId('button'); await userEvent.click(button); expect(onClose).toHaveBeenCalledTimes(0); expect(onClickButton).toHaveBeenCalledTimes(1); await userEvent.click(modal); expect(onClose).toHaveBeenCalledTimes(1); expect(onClickButton).toHaveBeenCalledTimes(1); }); });