emberjs / ember-test-helpers

Test-framework-agnostic helpers for testing Ember.js applications
Apache License 2.0
188 stars 254 forks source link

Improve touch event support #687

Open ggayowsky opened 5 years ago

ggayowsky commented 5 years ago

Currently, creating trying to create touch events with this library is very manual at best. Can can call triggerEvent with the type being 'touchstart', 'touchmove', 'touchend' or 'touchcancel' however a generic UIEvent (not a TouchEvent) will be created and sent.

Would be nice for this library to include better support for touch events.

rwjblue commented 5 years ago

We already have tap, and I am not particularly opposed to other touch specific helper methods. What do you have in mind?

ggayowsky commented 5 years ago

I am referring to having better triggerEvent support for touch events. Looking at fire-event.ts for mouse events (click, mouseup, mousemove, etc) a MouseEvent is returned and similarly for keyboard events a KeyboardEvent is returned, if the browser supports them. Also with mouse and keyboards event the library does some basic setup (add clientX and clientY in the case of mouse event)

For touch events, it just falls to the default handler which returns an Event instead of a TouchEvent, so I figured this library could simulate touch events a little better i.e. returning a TouchEvent if the browser supports it, initializing the event with the targetTouches (for touchStart) or changedTouches (for touchmove, touchend touchcancel), etc.

I have some code in my application that does some of this setup I will try to open a PR when I get the chance.

rwjblue commented 5 years ago

I have a mini library in my application that does some of this setup I will try to open a PR when I get the chance.

Sounds great! Definitely seems like an improvement.