title: jsdom: dispatchEvent/addEventListener doesn't seem to work
body: <p><strong>Summary:</strong></p>
  
  <p>I am attempting to test a React component that listens to native DOM events in its <code>componentWillMount</code>. </p>
  
  <p>I'm finding that jsdom (<code>@8.4.0</code>) doesn't work as expected when it comes to dispatching events and adding event listeners.</p>
  
  <p>The simplest bit of code I can extract:</p>
  
  <pre><code>window.addEventListener('click', () =&gt; {
    throw new Error("success")
  })
  
  const event = new Event('click')
  document.dispatchEvent(event)
  
  throw new Error('failure')
  </code></pre>
  
  <p>This throws "failure".</p>
  
  <hr>
  
  <p><strong>Context:</strong></p>
  
  <p>At risk of the above being an <a href="https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem">XY problem</a>, I want to provide more context.</p>
  
  <p>Here is an extracted/simplified version of the component I'm trying to test. <a href="http://www.webpackbin.com/NktFmumgb" rel="noreferrer">You can see it working on Webpackbin.</a></p>
  
  <pre><code>import React from 'react'
  
  export default class Example extends React.Component {
    constructor() {
      super()
      this._onDocumentClick = this._onDocumentClick.bind(this)
    }
  
    componentWillMount() {
      this.setState({ clicked: false })
      window.addEventListener('click', this._onDocumentClick)
    }
  
    _onDocumentClick() {
      const clicked = this.state.clicked || false
      this.setState({ clicked: !clicked })
    }
  
  
    render() {
      return &lt;p&gt;{JSON.stringify(this.state.clicked)}&lt;/p&gt;
    }
  }
  </code></pre>
  
  <p>Here is the test I'm trying to write.</p>
  
  <pre><code>import React from 'react'
  import ReactDOM from 'react-dom'
  import { mount } from 'enzyme'
  
  import Example from '../src/example'
  
  describe('test', () =&gt; {
    it('test', () =&gt; {
      const wrapper = mount(&lt;Example /&gt;)
  
      const event = new Event('click')
      document.dispatchEvent(event)
  
      // at this point, I expect the component to re-render,
      // with updated state.
  
      expect(wrapper.text()).to.match(/true/)
    })
  })
  </code></pre>
  
  <p>Just for completeness, here is my <code>test_helper.js</code> which initializes jsdom:</p>
  
  <pre><code>import { jsdom } from 'jsdom'
  import chai from 'chai'
  
  const doc = jsdom('&lt;!doctype html&gt;&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;')
  const win = doc.defaultView
  
  global.document = doc
  global.window = win
  
  Object.keys(window).forEach((key) =&gt; {
    if (!(key in global)) {
      global[key] = window[key]
    }
  })
  </code></pre>
  
  <hr>
  
  <p><strong>Reproduction case:</strong></p>
  
  <p>I have a repro case here: <a href="https://github.com/jbinto/repro-jsdom-events-not-firing" rel="noreferrer">https://github.com/jbinto/repro-jsdom-events-not-firing</a></p>
  
  <p><code>
  git clone https://github.com/jbinto/repro-jsdom-events-not-firing.git
  cd repro-jsdom-events-not-firing
  npm install
  npm test
  </code></p>