title: ERROR: Expected mock function to have been called
body: <p>I am trying to test onClick of a span tag of a react component. </p>
  
  <pre><code>&lt;span id="A" onClick={this.changeImage}&gt; Image A&lt;/span&gt;
  </code></pre>
  
  <p>Want to test if 'onClick' the 'changeImage' function is being called or not!</p>
  
  <p>// test.js</p>
  
  <pre><code>describe('Tests', () =&gt; {
  const wrapper = shallow(&lt;Image /&gt;);
  it('Should render without exploading', () =&gt; {
      expect(wrapper).toHaveLength(1);
  });
  
  it('Should call changeImage() function on click', () =&gt; {
      wrapper.instance().changeImage = jest.fn();
      wrapper.update();
      wrapper.find('#A').simulate('click', { target: { id: 'A' } });
      expect(wrapper.instance().changeImage).toHaveBeenCalled();
      });
  });
  </code></pre>
  
  <p>Also tried this - </p>
  
  <pre><code>it('Should call changeImage() function on click', () =&gt; {
      const spy = jest.spyOn(wrapper.instance(), 'changeImage');
      wrapper.find('#A').simulate('click', { target: { id: 'A' } });
      expect(spy).toHaveBeenCalled();
  });
  </code></pre>
  
  <p>Both returning the same error. 
  // Error</p>
  
  <pre><code>● Tests › Should call changeImage() function on click
  
  expect(jest.fn()).toHaveBeenCalled()
  
  Expected mock function to have been called.
  </code></pre>
  
  <p>Can someone please point out what am I doing wrong? Thanks.</p>