title: How to mock a React component lifecycle method with Jest and Enzyme?
body: <p>The Enzyme docs for Full DOM Rendering <a href="http://airbnb.io/enzyme/docs/api/mount.html" rel="noreferrer">here</a> contains the following example of spying on a lifecycle method with Sinon:</p>
  
  <pre class="lang-js prettyprint-override"><code>describe('&lt;Foo /&gt;', () =&gt; {
  
    it('calls componentDidMount', () =&gt; {
      sinon.spy(Foo.prototype, 'componentDidMount');
      const wrapper = mount(&lt;Foo /&gt;);
      expect(Foo.prototype.componentDidMount.calledOnce).to.equal(true);
    });
  });
  </code></pre>
  
  <p>What is the equivalent to this using mock functions from Jest? </p>
  
  <p>I'm using Create-React-App, and would rather not include Sinon if the same can be achieved with Jest.</p>
  
  <p>Here's what I'd expect the test to look like:</p>
  
  <pre class="lang-js prettyprint-override"><code>describe('&lt;App /&gt;', () =&gt; {
  
    it('calls componentDidMount', () =&gt; {
      jest.fn(App.prototype, 'componentDidMount');
      const wrapper = mount(&lt;App /&gt;);
      expect(App.prototype.componentDidMount.mock.calls.length).toBe(1);
    });
  });
  </code></pre>
  
  <p>In this case, <code>App.prototype.componentDidMount</code> doesn't reference the same function spy as it would do with Sinon.</p>
  
  <p>The Jest docs on how mock functions actually work are a bit limited. I've followed the discussion <a href="https://github.com/facebook/jest/issues/1592" rel="noreferrer">here</a> around what jest.fn() is doing, but it seems it's not really equivalent to sinon.spy().</p>
  
  <p>How can I replicate that test with Jest?</p>