react-testing-library, check if component method was called

Viewed 3809

Using '@testing-library/react',

given the following component:

const Home = () => {
   const submit = () => console.log('submit clicked');

   return (
     <div>
       Home
      <Button
        onClick={submit}
      >
        Submit
      </Button>
     </div>
   )
}

What assertion is necessary to add in order to finish the test below?

it('reacts to a submit event', async () => {
    const { getByText } = render(<Home />);

    fireEvent.click(getByText(/submit/i));
  })
0 Answers
Related