emberjs / emberjs/ember-test-helpers

Return the event which is triggered by a DOM event helper

Open
#440 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
188
Forks
254
PR merge metrics
No merged PRs in 30d

Description

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:
```js
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.