Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way to emit events in test code that is compatible with propagating-hammerjs #2

Closed
kbullaughey opened this issue Feb 8, 2015 · 4 comments
Labels

Comments

@kbullaughey
Copy link

I started using propagating-hammerjs which works fine for my app but broke my tests. I realized I could fix my failing tests by emitting an additional event before each simulated event with something like the following:

hammerInstance.emit('hammer.input', {target: event.target, isFirst: true})
hammerInstance.emit(eventType, event)

I'm curious if this is the recommended way to simulate events in a propagating-hammerjs compatible way? Or is there a better way to simulate events that will work out of the box? or is there a way that propagating-hammerjs could be improved in such a way that the requisite setup for simulated events will have happened without manually needing to do it?

@josdejong
Copy link
Owner

The closer to hammer.js the better. Best would be if this library wouldn't be necessary at all ;).

This is an interesting case, so far I hadn't used emit and therefore didn't encounter this issue. I think this problem boils down to the internal property _firstTarget not being set in case of an event fired via emit.

I've added some code overriding hammers emit event, see ff7b6a7. Can you check whether this solves the issue?

@josdejong josdejong added the bug label Feb 9, 2015
@kbullaughey
Copy link
Author

Yes. That fix allowed me to remove the extra emit() in my tests.

btw, I was using emit in my tests because that's what I saw you doing in your tests. Is this the best way for me to be testing my app's use of hammerjs? I manually create an event object that is an ordinary javascript object (not an Event) and fill in the details that hammerjs uses. But this required some trial an error, and inspection of hammerjs's source code to get working. It's also probably rather brittle. It's also not easy to simulate more elaborate gestures.

Is there a better way to do this? Does hammerjs expose an interface (other than emit) that works well for simulating events during tests?

@josdejong
Copy link
Owner

Ok great that it works.

I'm not sure which tests you mean, at least propagating-hammerjs doesn't have tests (sorry for that).

@josdejong
Copy link
Owner

I don't know what is the preferred way to test touch events with hammer. I suppose the "right" way is to create real DOM events and fire them via real DOM event handlers attached to real DOM elements. But that's not so trivial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants