|
12 | 12 | Returns a promise which will resolve when rendering has completed. In
|
13 | 13 | this context, rendering is completed when all auto-tracked state that is
|
14 | 14 | consumed in the template (including any tracked state in models, services,
|
15 |
| - etc. that are then used in a template) has been updated in the DOM. |
16 |
| -
|
17 |
| - For example, in a test you might want to update some tracked state and |
18 |
| - then run some assertions after rendering has completed. You _could_ use |
19 |
| - `await settled()` in that location, but in some contexts you don't want to |
20 |
| - wait for full settledness (which includes test waiters, pending AJAX/fetch, |
21 |
| - run loops, etc) but instead only want to know when that updated value has |
22 |
| - been rendered in the DOM. **THAT** is what `await renderSettled()` is _perfect_ |
23 |
| - for. |
| 15 | + etc. that are then used in a template) has been updated in the DOM. |
| 16 | +
|
| 17 | + For example, in a test you might want to update some tracked state and |
| 18 | + then run some assertions after rendering has completed. You _could_ use |
| 19 | + `await settled()` in that location, but in some contexts you don't want to |
| 20 | + wait for full settledness (which includes test waiters, pending AJAX/fetch, |
| 21 | + run loops, etc) but instead only want to know when that updated value has |
| 22 | + been rendered in the DOM. **THAT** is what `await renderSettled()` is |
| 23 | + _perfect_ for. |
| 24 | +
|
| 25 | + ```js |
| 26 | + import { renderSettled } from '@ember/renderer'; |
| 27 | + import { render } from '@ember/test-helpers'; |
| 28 | + import { tracked } from '@glimmer/tracking'; |
| 29 | + import { hbs } from 'ember-cli-htmlbars'; |
| 30 | + import { setupRenderingTest } from 'my-app/tests/helpers'; |
| 31 | + import { module, test } from 'qunit'; |
| 32 | +
|
| 33 | + module('Integration | Component | profile-card', function (hooks) { |
| 34 | + setupRenderingTest(hooks); |
| 35 | +
|
| 36 | + test("it renders the person's name", async function (assert) { |
| 37 | + class Person { |
| 38 | + @tracked name = ''; |
| 39 | + } |
| 40 | +
|
| 41 | + this.person = new Person(); |
| 42 | + this.person.name = 'John'; |
| 43 | +
|
| 44 | + await render(hbs` |
| 45 | + <ProfileCard @name={{this.person.name}} /> |
| 46 | + `); |
| 47 | +
|
| 48 | + assert.dom(this.element).hasText('John'); |
| 49 | +
|
| 50 | + this.person.name = 'Jane'; |
| 51 | +
|
| 52 | + await renderSettled(); // Wait until rendering has completed. |
| 53 | +
|
| 54 | + assert.dom(this.element).hasText('Jane'); |
| 55 | + }); |
| 56 | + }); |
| 57 | + ``` |
| 58 | +
|
24 | 59 | @method renderSettled
|
25 | 60 | @returns {Promise<void>} a promise which fulfills when rendering has completed
|
26 | 61 | @public
|
|
0 commit comments