Skip to content

Commit

Permalink
Update 'triggerEvent' examples
Browse files Browse the repository at this point in the history
- Fix missing line break in first `triggerEvent` example.
- Include additional example for simulating the `drop` event.
  • Loading branch information
Quinten Powell committed Jun 7, 2019
1 parent 9331615 commit bf014a4
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions API.md
Expand Up @@ -308,8 +308,9 @@ Triggers an event on the specified target.

#### Examples

Using triggerEvent to Upload a file
When using triggerEvent to upload a file the `eventType` must be `change` and you must pass the
Using `triggerEvent` to upload a file

When using `triggerEvent` to upload a file the `eventType` must be `change` and you must pass the
`options` param as an object with a key `files` containing an array of
[Blob][56].

Expand All @@ -318,10 +319,29 @@ When using triggerEvent to upload a file the `eventType` must be `change` and yo
triggerEvent(
'input.fileUpload',
'change',
[new Blob(['Ember Rules!'])]
{
files: [new Blob(['Ember Rules!'])]
}
);
```

Using `triggerEvent` to upload a dropped file

When using `triggerEvent` to handle a dropped (via drag-and-drop) file, the `eventType` must be `drop`. Assuming your `drop` event handler uses the [DataTransfer API][64], you must pass the `options` param as an object with a key of `dataTransfer`. The `options.dataTransfer` object should have a `files` key, containing an array of [File][63].

```javascript
triggerEvent(
'[data-test-drop-zone]',
'drop',
{
dataTransfer: {
files: [new File(['Ember Rules!', 'ember-rules.txt'])]
}
}
)
```


Returns **[Promise][53]<void>** resolves when the application is settled

### triggerKeyEvent
Expand Down Expand Up @@ -984,3 +1004,6 @@ QUnit.testDone(function() {
[61]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[62]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function

[63]: https://developer.mozilla.org/en-US/docs/Web/API/File
[64]: https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer

0 comments on commit bf014a4

Please sign in to comment.