title: Trigger callback from external component react testing library
body: <p>I am trying to figure out how to test callbacks that are given as props to react functional components using jest and react testing library.</p>
  <p>Example scenario: I am testing a component that renders a modal. When a user clicks the 'Close' button on the modal, the parent component hides the modal. So logic is this:</p>
  <pre><code> const ParentComp = () =&gt; {
    const [openModal, setOpenModal] = useState(false);
    return (
     &lt;&gt;
       &lt;MyModal showModal={openModal} onClose={() =&gt; setOpenModal(false)} /&gt;
       &lt;button data-testid=&quot;open-modal-button&quot; onClick={()=&gt; setOpenModal(true)}&gt;Test&lt;/button&gt;
    &lt;/&gt;
   }
  
  const MyModal = ({showModal, onClose}) =&gt; {
    return (
     {showModal &amp;&amp; &lt;&gt;
       &lt;div&gt;This is a modal&lt;/div&gt;
       &lt;button data-testid=&quot;close-modal-button&quot; onClick={onClose}&gt;Close&lt;/button&gt;
    &lt;/&gt;
    }
   }
  </code></pre>
  <p>I am mocking the modal in my tests for the parent component as I dont want to rely on the actual modal component. With react testing library, how do I trigger the onClose in my parent component so I can test the setOpenModal(false)?</p>
  <pre><code>jest.mock('../MyModal');
  beforeEach(() =&gt; {
    MyModal.mockImplementation(() =&gt; &lt;div data-testid=&quot;my-modal&quot; /&gt;);
  });
  
  it('should close the modal' () =&gt; {
  const { container, getByTestId } = render(
      &lt;MyParentComp /&gt;
  );
  const openModalButton = getByTestId('open-modal-button');
  
  fireEvent.click(openModalButton);
  const myModal = getByTestId('my-modal');
  
  expect(myModal).toBeDefined();
  
  //How to test setOpenModal(false) on parent component?
  </code></pre>
  <p>});</p>