From ee412cc03b98bc39841aece93a387dab76e9840b Mon Sep 17 00:00:00 2001 From: Jen Weber Date: Wed, 11 Dec 2019 22:56:51 -0500 Subject: [PATCH 1/3] [DOC] Add examples to waitUntil and waitFor --- API.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/API.md b/API.md index 02a59da5e..b1fcfb810 100644 --- a/API.md +++ b/API.md @@ -503,6 +503,12 @@ interim DOM states (e.g. loading states, pending promises, etc). Returns **[Promise][54]<([Element][53] \| [Array][64]<[Element][53]>)>** resolves when the element(s) appear on the page +#### Examples + +```javascript +await waitFor('.my-selector', { timeout: 2000 }) +``` + ### waitUntil Wait for the provided callback to return a truthy value. @@ -519,6 +525,14 @@ while _not_ settled (e.g. "loading" or "pending" states). Returns **[Promise][54]** resolves with the callback value when it returns a truthy value +#### Examples + +```javascript +await waitUntil(function() { + return find('.my-selector').textContent.includes('something') +}, { timeout: 2000 }) +``` + ### settled Returns a promise that resolves when in a settled state (see `isSettled` for From 7b0584c266f2b47a2f3cd04dcc3e757c812c68bb Mon Sep 17 00:00:00 2001 From: Jen Weber Date: Thu, 23 Jan 2020 19:27:12 -0500 Subject: [PATCH 2/3] Adding docs examples for waitFor, waitIUntil --- API.md | 18 ++++++++++++------ .../@ember/test-helpers/dom/wait-for.ts | 7 +++++++ .../@ember/test-helpers/wait-until.ts | 9 +++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/API.md b/API.md index b1fcfb810..449623554 100644 --- a/API.md +++ b/API.md @@ -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 @@ -501,14 +501,17 @@ 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`) -Returns **[Promise][54]<([Element][53] \| [Array][64]<[Element][53]>)>** resolves when the element(s) appear on the page - #### 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 Wait for the provided callback to return a truthy value. @@ -523,16 +526,19 @@ 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'`) -Returns **[Promise][54]** resolves with the callback value when it returns a truthy value - #### Examples +Waiting until a selected element displays text + + ```javascript await waitUntil(function() { - return find('.my-selector').textContent.includes('something') +return find('.my-selector').textContent.includes('something') }, { timeout: 2000 }) ``` +Returns **[Promise][54]** resolves with the callback value when it returns a truthy value + ### settled Returns a promise that resolves when in a settled state (see `isSettled` for diff --git a/addon-test-support/@ember/test-helpers/dom/wait-for.ts b/addon-test-support/@ember/test-helpers/dom/wait-for.ts index b5a8a47bd..9a54e7f50 100644 --- a/addon-test-support/@ember/test-helpers/dom/wait-for.ts +++ b/addon-test-support/@ember/test-helpers/dom/wait-for.ts @@ -20,6 +20,13 @@ 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} resolves when the element(s) appear on the page + + @example + + Waiting until a selector is rendered + + + await waitFor('.my-selector', { timeout: 2000 }) */ export default function waitFor( selector: string, diff --git a/addon-test-support/@ember/test-helpers/wait-until.ts b/addon-test-support/@ember/test-helpers/wait-until.ts index cdcbe2e29..5b55385ba 100644 --- a/addon-test-support/@ember/test-helpers/wait-until.ts +++ b/addon-test-support/@ember/test-helpers/wait-until.ts @@ -22,6 +22,15 @@ 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 + + Waiting until a selected element displays text + + + await waitUntil(function() { + return find('.my-selector').textContent.includes('something') + }, { timeout: 2000 }) */ export default function waitUntil( callback: () => T | void | Falsy, From ac98870afb3a9a223abdeedca21dc836b8739629 Mon Sep 17 00:00:00 2001 From: Jen Weber Date: Thu, 23 Jan 2020 19:30:57 -0500 Subject: [PATCH 3/3] punctuation --- API.md | 4 ++-- addon-test-support/@ember/test-helpers/dom/wait-for.ts | 3 +-- addon-test-support/@ember/test-helpers/wait-until.ts | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/API.md b/API.md index 449623554..357f14736 100644 --- a/API.md +++ b/API.md @@ -503,7 +503,7 @@ interim DOM states (e.g. loading states, pending promises, etc). #### Examples -Waiting until a selector is rendered +Waiting until a selector is rendered: ```javascript @@ -528,7 +528,7 @@ while _not_ settled (e.g. "loading" or "pending" states). #### Examples -Waiting until a selected element displays text +Waiting until a selected element displays text: ```javascript diff --git a/addon-test-support/@ember/test-helpers/dom/wait-for.ts b/addon-test-support/@ember/test-helpers/dom/wait-for.ts index 9a54e7f50..cca1bcaad 100644 --- a/addon-test-support/@ember/test-helpers/dom/wait-for.ts +++ b/addon-test-support/@ember/test-helpers/dom/wait-for.ts @@ -23,9 +23,8 @@ export interface Options { @example - Waiting until a selector is rendered + Waiting until a selector is rendered: - await waitFor('.my-selector', { timeout: 2000 }) */ export default function waitFor( diff --git a/addon-test-support/@ember/test-helpers/wait-until.ts b/addon-test-support/@ember/test-helpers/wait-until.ts index 5b55385ba..064b31f9f 100644 --- a/addon-test-support/@ember/test-helpers/wait-until.ts +++ b/addon-test-support/@ember/test-helpers/wait-until.ts @@ -25,9 +25,8 @@ export interface Options { @example - Waiting until a selected element displays text + Waiting until a selected element displays text: - await waitUntil(function() { return find('.my-selector').textContent.includes('something') }, { timeout: 2000 })