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 examples to waitUntil and waitFor #750

Merged
merged 3 commits into from
Feb 5, 2020
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
22 changes: 21 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Emulating pressing the `ENTER` key on a button using `triggerKeyEvent`
triggerKeyEvent('button', 'keydown', 'Enter');
```

Returns **[Promise][54]<void>** resolves when the application is settled
Returns **[Promise][54]<void>** resolves when the application is settled unless awaitSettled is false

### typeIn

Expand Down Expand Up @@ -501,6 +501,15 @@ interim DOM states (e.g. loading states, pending promises, etc).
- `options.timeout` **[number][62]** the time to wait (in ms) for a match (optional, default `1000`)
- `options.count` **[number][62]** the number of elements that should match the provided selector (null means one or more) (optional, default `null`)

#### Examples

Waiting until a selector is rendered:


```javascript
await waitFor('.my-selector', { timeout: 2000 })
```

Returns **[Promise][54]<([Element][53] \| [Array][64]<[Element][53]>)>** resolves when the element(s) appear on the page

### waitUntil
Expand All @@ -517,6 +526,17 @@ while _not_ settled (e.g. "loading" or "pending" states).
- `options.timeout` **[number][62]** the maximum amount of time to wait (optional, default `1000`)
- `options.timeoutMessage` **[string][52]** the message to use in the reject on timeout (optional, default `'waitUntil timed out'`)

#### Examples

Waiting until a selected element displays text:


```javascript
await waitUntil(function() {
return find('.my-selector').textContent.includes('something')
}, { timeout: 2000 })
```

Returns **[Promise][54]** resolves with the callback value when it returns a truthy value

### settled
Expand Down
6 changes: 6 additions & 0 deletions addon-test-support/@ember/test-helpers/dom/wait-for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export interface Options {
@param {number} [options.timeout=1000] the time to wait (in ms) for a match
@param {number} [options.count=null] the number of elements that should match the provided selector (null means one or more)
@return {Promise<Element|Element[]>} resolves when the element(s) appear on the page

@example
<caption>
Waiting until a selector is rendered:
</caption>
await waitFor('.my-selector', { timeout: 2000 })
*/
export default function waitFor(
selector: string,
Expand Down
8 changes: 8 additions & 0 deletions addon-test-support/@ember/test-helpers/wait-until.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export interface Options {
@param {number} [options.timeout=1000] the maximum amount of time to wait
@param {string} [options.timeoutMessage='waitUntil timed out'] the message to use in the reject on timeout
@returns {Promise} resolves with the callback value when it returns a truthy value

@example
<caption>
Waiting until a selected element displays text:
</caption>
await waitUntil(function() {
return find('.my-selector').textContent.includes('something')
}, { timeout: 2000 })
*/
export default function waitUntil<T>(
callback: () => T | void | Falsy,
Expand Down