title: Testing a component that uses React.useEffect using enzyme
body: <p>Let's say I have this functional React component.</p>
  
  <pre><code>const SomeComponent = ({ onShow }) =&gt; {
    React.useEffect(onShow, []);
    return &lt;div /&gt;;
  };
  </code></pre>
  
  <p>Now I want to unit test that <code>SomeComponent</code> calls onShow the first time it is rendered. </p>
  
  <p>Is that possible using <code>enzyme</code>?</p>
  
  <hr>
  
  <p>I have tried implementing two very similar tests, the difference being that the first is using enzyme, the other one using react-testing-library.</p>
  
  <p>The test that uses react-testing-library passes, but the enzyme test fails, even though they test the same code.</p>
  
  <p>Example: </p>
  
  <pre><code>import * as reactTestingLibrary from "react-testing-library";
  import * as React from "react";
  import * as enzyme from "enzyme";
  
  const SomeComponent = ({ onShow }) =&gt; {
    React.useEffect(onShow, []);
    return &lt;div /&gt;;
  };
  
  describe("Testing useEffect with enzyme", () =&gt; {
    it("calls the side effect", async () =&gt; {
      const aFn = jest.fn();
      enzyme.mount(&lt;SomeComponent onShow={aFn} /&gt;);
      expect(aFn).toHaveBeenCalledTimes(1); // this test fails
    });
  });
  
  describe("Testing useEffect with react-testing-library", () =&gt; {
    it("calls the side effect", async () =&gt; {
      const aFn = jest.fn();
      reactTestingLibrary.render(&lt;SomeComponent onShow={aFn} /&gt;);
      expect(aFn).toHaveBeenCalledTimes(1); // this test passes
    });
  });
  </code></pre>
  
  <p>Is there a way to make enzyme execute the hook and pass the test?</p>