title: How can I test an internal method inside a component in React?
body: <p>I am trying to test spy a method used inside a React component but I am failing. The component is the below : </p>
  
  <pre><code>export class SiderMenu extends PureComponent {
  
  formatter(data, parentPath = '', parentAuthority) {
    return data.map((item) =&gt; {
    const result = {
      ...item,
      path: `${parentPath}${item.path}`,
    };
    return result;
  });
  }
  constructor(props) {
    super(props);
    this.menus = this.formatter(props.menuData);
  }
  render(....)
  }
  </code></pre>
  
  <p>I am using enzyme and I want to test that the formatter method has been called: </p>
  
  <pre><code>describe.only('SiderMenu.formatter', () =&gt; {
    it('Expect to have been called', () =&gt; {
    // const spy = jest.spyOn(SiderMenu.prototype, 'formatter');
    const wrapper = shallow(&lt;SiderMenu /&gt;);
    const instance = wrapper.instance();
    const method = jest.spyOn(instance, 'formatter');
    expect(method).toHaveBeenCalled();
    });
   });
  </code></pre>
  
  <p>I tried also to spy the method using the prototype of the component but I constantly taking the below error</p>
  
  <blockquote>
    <p>TypeError: Cannot read property '_isMockFunction' of undefined</p>
  </blockquote>
  
  <p>This error is created by the 'jest.spyOn(instance, 'formatter');'. Can someone help me out about this ? How can I test that formatter method has been called ? </p>