Skip to content

Commit

Permalink
Add some specific documentation for uploading files
Browse files Browse the repository at this point in the history
Uploading files with an event is a specific code path and the task can
be tough to figure out without an example.
  • Loading branch information
jrjohnson committed Apr 18, 2018
1 parent 7f9a3d0 commit 829f4fb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
14 changes: 14 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ Triggers an event on the specified target.
- `eventType` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the type of event to trigger
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** additional properties to be set on the event

**Examples**

_Using triggerEvent to Upload a file
When using triggerEvent to upload a file the `eventType` must be `change` and you must pass an
array of [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) as `options`._

```javascript
triggerEvent(
'input.fileUpload',
'change',
[new Blob(['Ember Rules!'])]
);
```

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<void>** resolves when the application is settled

### triggerKeyEvent
Expand Down
27 changes: 19 additions & 8 deletions addon-test-support/@ember/test-helpers/dom/trigger-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@ import settled from '../settled';
import { nextTickPromise } from '../-utils';

/**
Triggers an event on the specified target.
@public
@param {string|Element} target the element or selector to trigger the event on
@param {string} eventType the type of event to trigger
@param {Object} options additional properties to be set on the event
@return {Promise<void>} resolves when the application is settled
*/
* Triggers an event on the specified target.
*
* @public
* @param {string|Element} target the element or selector to trigger the event on
* @param {string} eventType the type of event to trigger
* @param {Object} options additional properties to be set on the event
* @return {Promise<void>} resolves when the application is settled
*
* @example
* <caption>Using triggerEvent to Upload a file
* When using triggerEvent to upload a file the `eventType` must be `change` and you must pass an
* array of [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) as `options`.</caption>
*
* triggerEvent(
* 'input.fileUpload',
* 'change',
* [new Blob(['Ember Rules!'])]
* );
*/
export default function triggerEvent(target, eventType, options) {
return nextTickPromise().then(() => {
if (!target) {
Expand Down

0 comments on commit 829f4fb

Please sign in to comment.