jquery / jquery-simulate

jQuery Event Unit Testing Helpers
Other
173 stars 114 forks source link

add support for UI events, including change #16

Closed AndersDJohnson closed 1 year ago

AndersDJohnson commented 11 years ago

Needed this to emulate native user-driven 'change' event on input elements, at least in Chrome 28, where jQuery's .change() and .trigger('change') failed me.

mikesherov commented 10 years ago

I know this is very old at this point, but thanks for contributing! Would you be able to add some unit tests for this change?

AndersDJohnson commented 10 years ago

Sure - basic unit test added to prove it fires, at least in my browser (Chrome 36.0.1985.143 m, Windows). As for other browsers, I am not sure.

How do you do cross-browser testing? I see some possible jQuery TestSwarm integration, but I'm not sure.

Though it seems to work for now, apparently change is not technically a UIEvent but a generic Event per DOM Level 2 via MDN Event reference. So we could have a generic Event implementation as well, and move change to it instead.

Did you mean this pull request is old, or the project is old?

mikesherov commented 10 years ago

I meant the pull request; Not your fault, mine. Thanks for adding the tests. I'll do some cross browser testing.

brian-mann commented 9 years ago

When will this get merged in? Is it ready to go?

Also, cancelable should be false, not true, as per the spec.

https://developer.mozilla.org/en-US/docs/Web/Events/change

AndersDJohnson commented 9 years ago

@brian-mann Are you asking me or @mikesherov? From my end it worked in Chrome 28-36 when I made the PR, but wasn't tested across various browsers.

Per my earlier comment, I still think it shouldn't be a UIEvent - I can try correct if there is interest.

brian-mann commented 9 years ago

I'm asking @mikesherov since he said he was doing some cross browser testing.

And yes, I believe the event should be HTMLEvents not UIEvent. This is a Dom Level 0 event.

AndersDJohnson commented 9 years ago

@brian-mann In order to correct cancelable and UIEvent->Event, I think this warrants some refactoring.

AndersDJohnson commented 9 years ago

@brian-mann I've just pushed some changes in c6a417d that address the above problems (change is now cancelable and HTMLEvents instead of UIEvents).

mikesherov commented 9 years ago

These changes look good, I've just been swamped with other work, and I missed the notifications earlier.

Some of this is a bit over my head, can you give me a short explanation of what firing advantages fire HTMLEvents has over what simulate is currently capable of?

AndersDJohnson commented 9 years ago

@mikesherov There are different kinds of browser events with different APIs. Currently this library supports key (KeyboardEvent) and mouse (MouseEvent) events only, not HTMLEvents such as change. To create these events correctly in a programmatic fashion, we need to add mappings from the event name strings to the correct event type interface.

See:

jzaefferer commented 9 years ago

Thank you for the contribution. As you've probably guessed already, this project isn't well maintained. I've added some details about that here: https://github.com/jquery/jquery-simulate#project-status