title: How to mock eventListener when set in componentDidMount()
body: <p>Thats my component</p>
  
  <pre><code>class Foo extends React.Component {
      constructor(props) {
          super(props);
  
          this.state = {
              ...
          };
  
          this.input = React.createRef();
      }
  
      componentDidMount() {
          const id = 'bar';
          let element = document.getElementById(id);
          element.addEventListener('transitionend', () =&gt; {
              this.setState({ ... });
          }, false);
      }
  
      ...
  </code></pre>
  
  <p>When I set up my test like so</p>
  
  <pre><code>import React from 'react';
  import { mount } from 'enzyme';
  import 'jsdom-global/register';
  
  import Foo from './';
  
  it('renders the component correctly', () =&gt; {
      const component = mount(
          &lt;Foo /&gt;
      );
  
      component
          .unmount();
  });
  </code></pre>
  
  <p>I get</p>
  
  <blockquote>
    <p>console.error node_modules/react-dom/cjs/react-dom.development.js:16647
    The above error occurred in the  component:
    in Foo (created by WrapperComponent)
    in WrapperComponent</p>
    
    <p>Consider adding an error boundary to your tree to customize error handling behavior.
    ● renders the component correctly
    TypeError: Cannot read property 'addEventListener' of null</p>
  </blockquote>
  
  <p>I tried </p>
  
  <pre><code>ReactDOM.render(&lt;Foo /&gt;, document.body);
  </code></pre>
  
  <p>or adding this</p>
  
  <pre><code>const map = {};
  Window.addEventListener = jest.genMockFn().mockImpl((event, cb) =&gt; {
    map[event] = cb;
  });
  </code></pre>
  
  <p>as well as this</p>
  
  <pre><code>const map = {};
      document.addEventListener = jest.fn((event, cb) =&gt; {
        map[event] = cb;
      })
  </code></pre>
  
  <p>before mounting <code>&lt;Foo /&gt;</code> in the test. But it all comes back with the same error. Why is that?</p>