Skip to content

Commit db982dd

Browse files
Merge pull request #516 from emberjs/NullVoxPopuli-patch-2
Update README.md for waitForFetch
2 parents 3f977b5 + 9522c73 commit db982dd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This addon implements the design specified in [RFC 581](https://github.com/ember
3030
- [Waiter naming conventions](#waiter-naming-conventions)
3131
- [waitForPromise function](#waitforpromise-function)
3232
- [waitFor function](#waitfor-function)
33+
- [waitForFetch function](#waitforfetch-function)
3334
- [Waiting on all waiters](#waiting-on-all-waiters)
3435
- [Best Practices](#best-practices)
3536
- [Use buildWaiter in module scope](#use-buildwaiter-in-module-scope)
@@ -192,6 +193,25 @@ export default class Friendz extends Component {
192193
193194
`waitFor` acts as a wrapper for the generator function, producing another generator function that is registered with the test waiter system, suitable for wrapping in an `ember-concurrency` task. So `@waitFor`/`waitFor()` needs to be applied directly to the generator function, and `@task`/`task()` applied to the result.
194195
196+
### waitForFetch function
197+
198+
Similar to `waitForPromise`, `waitForFetch` wraps the `fetch` promise, but also wraps the response parsing functions, `text`, `json`, etc.
199+
200+
201+
```js
202+
import Component from '@glimmer/component';
203+
import { waitForFetch } from '@ember/test-waiters';
204+
205+
export default class MoreFriendz extends Component {
206+
async funcWithAsync() {
207+
let response = await waitForFetch(fetch('...'));
208+
209+
// automatically wrapped it waitForPromise
210+
return await response.json();
211+
}
212+
}
213+
```
214+
195215
### Waiting on all waiters
196216
197217
The `@ember/test-waiters` addon provides a `waiter-manager` to register, unregister, iterate and invoke waiters to determine if we should wait for conditions to be met or continue test execution. This functionality is encapsulated in the `hasPendingWaiters` function, which evaluates each registered waiter to determine its current state.

0 commit comments

Comments
 (0)