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