title: spy on method call in componentDidMount
body: <p>I want to test some custom methods that get called in the componentDidMount life cycle method of a React component. </p>
  
  <pre><code>  componentDidMount() {
      getData().then(res =&gt; {
        console.log(res);
        this.setState({
          rate: res.data.bpi.USD.rate_float
        });
      });
    }
  </code></pre>
  
  <p>I am importing the getData method from api.js:</p>
  
  <pre><code>export const getData = () =&gt; {
    return axios
      .get("https://api.coindesk.com/v1/bpi/currentprice.json")
      .then(res =&gt; {
        return res;
      });
  };
  </code></pre>
  
  <p>Testing it with Jest and Enyzme like this:</p>
  
  <pre><code>describe("App", () =&gt; {
    describe("Calls getData when componentDidMount", () =&gt; {
      const spy = jest.spyOn(App.prototype, "getData");
      const wrapper = mount(&lt;App {...props} /&gt;);
      wrapper.instance().getData();
      expect(spy).toHaveBeenCalled(1);
    });
  });
  </code></pre>
  
  <p>It fails: <code>App › Calls getData when componentDidMount › encountered a declaration exception</code></p>
  
  <p>And give me the following error: </p>
  
  <pre><code>TypeError: Cannot read property '_isMockFunction' of undefined
  </code></pre>
  
  <p>What are I am doing wrong? </p>