-
-
Notifications
You must be signed in to change notification settings - Fork 251
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
Standarise the fireEvent
method interface
#399
Standarise the fireEvent
method interface
#399
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though, buildFileEvent accepts an array: files = [], the documentation doesn't clarify this difference.
buildFileEvent
is a private API and should not be used directly, therefore any documentation for this scenario should be in triggerEvent
. Can you add additional examples to those inline docs to show how to trigger change on a file input?
Should we start writing a test for this file? I think it is a sensitive one to skip tests on.
Every test we have around eventing is testing fire-event
, it is covered fairly well in general but there may be specific event types that are not. We should enumerate the event types and ensure that we have at least one test for each...
let event = buildBasicEvent(type); | ||
let files = options.files || []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written, this is a breaking change. As mentioned in the PR description, anyone using triggerEvent
for this today must pass an array, if we are going to change this to { files: someArray }
as you suggest here, we definitely need to detect if options
is already an array...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we are going to change this to { files: someArray } as you suggest here, we definitely need to detect if options is already an array...
@rwjblue that makes sense. My first thought is to disambiguate this in the documentation itself, but then as a novice user of this add on, I would have expected that the interface to accept { files: someArray }
, hence why I felt it might be a more natural (but breaking change) step to standarize it.
Thank you @rwjblue for taking a look. To summarise, I could take these two actions, as you suggested:
Does this sound like a good way to move forward? |
Yep, sounds good to me! |
0efac39
to
9e6a980
Compare
@rwjblue does it make sense the way it looks now? |
When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure. Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference. I think it will be more natural not to break the interface here by introducing an array argument. Standarise the `fireEvent` method interface When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure. Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference. I think it will be more natural not to break the interface here by introducing an array argument. Standarise the `fireEvent` method interface When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure. Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference. I think it will be more natural not to break the interface here by introducing an array argument. Apply PR feedback 1. Added an example to the documentation of the `triggerEvent` to elaborate on how to trigger a change event for a file. 2. Added logic for detecting if options is already an array. This commit allows us to avoid introducing breaking changes, and maintain an expectation of providing `files` array in the `options` object for the `triggerEvent` method. Standarise the `fireEvent` method interface When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure. Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference. I think it will be more natural not to break the interface here by introducing an array argument. Apply PR feedback 1. Added an example to the documentation of the `triggerEvent` to elaborate on how to trigger a change event for a file. 2. Added logic for detecting if options is already an array. This commit allows us to avoid introducing breaking changes, and maintain an expectation of providing `files` array in the `options` object for the `triggerEvent` method. Fix lint offense Fix lint offense Standarise the `fireEvent` method interface When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure. Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference. I think it will be more natural not to break the interface here by introducing an array argument. Apply PR feedback 1. Added an example to the documentation of the `triggerEvent` to elaborate on how to trigger a change event for a file. 2. Added logic for detecting if options is already an array. This commit allows us to avoid introducing breaking changes, and maintain an expectation of providing `files` array in the `options` object for the `triggerEvent` method. Fix lint offense Standarise the `fireEvent` method interface When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure. Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference. I think it will be more natural not to break the interface here by introducing an array argument. Apply PR feedback 1. Added an example to the documentation of the `triggerEvent` to elaborate on how to trigger a change event for a file. 2. Added logic for detecting if options is already an array. This commit allows us to avoid introducing breaking changes, and maintain an expectation of providing `files` array in the `options` object for the `triggerEvent` method. Fix lint offense Fix lint offense Standarise the `fireEvent` method interface When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure. Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference. I think it will be more natural not to break the interface here by introducing an array argument. Apply PR feedback 1. Added an example to the documentation of the `triggerEvent` to elaborate on how to trigger a change event for a file. 2. Added logic for detecting if options is already an array. This commit allows us to avoid introducing breaking changes, and maintain an expectation of providing `files` array in the `options` object for the `triggerEvent` method. Fix lint offense Fix lint offense Fix identation in the docs Fix lint issues
9e6a980
to
5ddfe54
Compare
let event = buildBasicEvent(type); | ||
let files = Array.isArray(options) ? options : options.files || []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we issue a deprecation or something when we do this coercion?
I'm just thinking that over time we probably only want to support one form...
* | ||
* // passing an array of files | ||
* let file = new File(['text file'], 'text.txt', { type: 'text/plain' }); | ||
* await triggerEvent('input:file', 'change', [file]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ultimately, we should only have one format here (probably the { files: [] }
one?)...
@khalilovcmd - Had a chance to review those questions? |
Will need to address merge conflicts from docs changes made in #340 |
@khalilovcmd - I'd still love to land this, any chance you mind have time to rebase and clean up soon? |
Why?
When using
triggerEvent
to fire achange
event on<input> element with type="file"
, those lines call thebuildFileEvent
which forwardsoptions
with its same structure.Though,
buildFileEvent
accepts an array:files = []
, the documentation doesn't clarify this difference.I think it will be more natural not to break the interface here by introducing an array argument.
Sample code
Questions
Alternatives
We could also live with elaborating on this difference in the
API.md
, to avoid breaking changes.cc: kudos to @mattdonnelly for pointing this out, and subsequently saving my day.