title: Jest spy on component's property method
body: <p>I'm trying to test if an event has been added in the init method called by componentDidMount, but that event is going to be added only if a component's attribute is set in "true" so I want to spy on the addEventHandler method and call the "toBeCalledWith('eventName')" so I have something like this:</p>
  
  <pre><code>export interface IMyComponentProps{
      flag?: boolean;
  }
  
  export class MyComponent extends Component&lt;IMyComponentProps&gt; {
      private myProperty: HTMLElement;
  
      public componentDidMount() {
          this.init();
      }
  
      private init() {
          if (this.props.flag) {
              this.myProperty.addEventListener("event", arg2, arg3);
          }
      }
  }
  </code></pre>
  
  <p>Then I have my test looking like this:</p>
  
  <pre><code>test("Test 1", () =&gt; {
     const spyInit = jest.spyOn(MyComponent.prototype, "init");
     wrapper = mount(
        &lt;MyComponent /&gt;
     );
  
     expect(spyInit).toBeCalled();
  })
  </code></pre>
  
  <p>but the test above does not cover if the addEventListener is called or not so I'm trying different ways like following, without success:</p>
  
  <pre><code>const spyAddListener = jest.spyOn(MyComponent.prototype, "myProperty.addEventHandler"); 
  const spyAddListener = jest.spyOn(MyComponent.instance().myProperty, "addEventHandler"); 
  const spyAddListener = jest.spyOn(MyComponent.prototype.myProperty, "addEventHandler");
  </code></pre>
  
  <p>any suggestion?</p>