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

Add some specific documentation for uploading files #340

Merged
merged 1 commit into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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