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

Return the event which is triggered by a DOM event helper #440

Open
bastimeyer opened this issue Oct 21, 2018 · 1 comment
Open

Return the event which is triggered by a DOM event helper #440

bastimeyer opened this issue Oct 21, 2018 · 1 comment

Comments

@bastimeyer
Copy link

Currently, none of the available DOM event helpers (triggerEvent, triggerKeyEvent, click, etc.) return the event which they have triggered on an element and instead return the value of the isSettled() call. This means that in cases where for example a component has prevented the browser's default action or has stopped the propagation of a certain event, this can't be tested by using the available DOM helpers of ember-test-helpers.

What is even the reason for returning the value of isSettled()? By looking at the code, it seems like the intention for this was to just chain the settled() promise in the returned event helper promise.

See this simple use case:

test( "foo", async function( assert ) {
  await render( hbs`{{foo-bar}}` );
  const event = await triggerEvent( ".foo-bar", "eventname" );
  assert.ok( event.defaultPrevented, "Prevents default action" );
});

I've been previously using jQuery for having a dead simple API to trigger DOM events in tests, but since Ember is slowly getting rid of jQuery (which is a good thing), the logical choice for devs is to stop using jQuery in tests, too, and using the helper methods of ember-test-helpers instead. But since the test helpers don't return the events which they are triggering, this is a problem in certain test scenarios.

@cibernox
Copy link
Contributor

cibernox commented Oct 21, 2018

@bastimeyer Right now every helper returns the value of calling settled(), which unless I'm wrong it is just a Promise<void>. What you are suggesting is that we change it so it returns Promise<Event>.

In ok with the idea in principle, as right now afaik we don't have any compromise of what the resolution value of the promises are. Changing from Promise<void> to Promise<Event> would give us more capabilities and wouldn't mess with existing code.

However it can be tricky for events like click or fillIn that in reality trigger several events.
Click, for instance, fires mousedown, focus, mouseup and then click.
We could just return click or return an object or array with all the fired events, but we'd have to decide what is the right thing to do first.

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

No branches or pull requests

2 participants