title: How do I programmatically create a TouchEvent in Chrome 41?
body: <p>I am trying to create a touch event for a unit test.  After reading <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent" rel="noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent</a>, I expected that I would be able to do:</p>
  
  <pre><code>document.createEvent('TouchEvent');
  </code></pre>
  
  <p>But I get this error:</p>
  
  <blockquote>
    <p>Uncaught DOMException: Failed to execute 'createEvent' on 'Document': The provided event type ('TouchEvent') is invalid.</p>
  </blockquote>
  
  <p>I saw <a href="https://stackoverflow.com/questions/5713393/creating-and-firing-touch-events-on-a-touch-enabled-browser">Creating and firing touch events on a touch enabled browser?</a>, which also seems to indicate that createEvent() is the way to go.</p>
  
  <p>I also tried creating the event via constructor, which works for, say,  MouseEvent and WheelEvent:</p>
  
  <pre><code>new window.TouchEvent()
  </code></pre>
  
  <p>But I get an error here, too:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Illegal constructor</p>
  </blockquote>
  
  <p>I tried in Firefox 36, but based on <a href="http://caniuse.com/#search=touch" rel="noreferrer">http://caniuse.com/#search=touch</a>, I wasn't surprised to see:</p>
  
  <blockquote>
    <p>NotSupportedError: Operation is not supported</p>
  </blockquote>
  
  <p>After running</p>
  
  <pre><code>document.createEvent('TouchEvent')
  </code></pre>
  
  <p>There is not event a window.TouchEvent constructor in Firefox, which is, again, not surprising.</p>
  
  <p>Any ideas what I am doing wrong?</p>