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:
I'm guessing the only way to do it without throwing an exception is to be more explicit in the type of event you wish to create:
var evt = document.createEvent('UIEvent');
evt.initUIEvent('touchstart', true, true);
The TouchEvent is a subclass of UIEvent.
Update
As mentioned above, while on an actual device (or emulating a device), one can easily create a TouchEvent using the standard document.createEvent method.
So perhaps a try/catch would be in order:
try {
document.createEvent('TouchEvent');
} catch (e) {
console.log('No touching!');
}