Skip to content

Commit 0dfb1dc

Browse files
Geodewd549chriskrycho
authored andcommitted
DOC: API: add render helper examples
Let's add an example usage of all of the render helpers (render, clearRender) to the API docs. (cherry picked from commit fb7d293) # Conflicts: # API.md # addon-test-support/@ember/test-helpers/setup-rendering-context.ts
1 parent 82f97e5 commit 0dfb1dc

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

API.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ Find all of the elements matching '.my-selector'.
501501
findAll('.my-selector');
502502
```
503503

504-
Returns **[Element][65]** matched element or null
504+
Returns **([Element][65] | null)** matched element or null
505505

506506
### findAll
507507

@@ -588,6 +588,14 @@ Renders the provided template and appends it to the DOM.
588588
* `templateOrComponent` **(Template | Component)** the component (or template) to render
589589
* `options` **RenderOptions** options hash containing engine owner ({ owner: engineOwner })
590590

591+
#### Examples
592+
593+
Render a div element with the class 'container'.
594+
595+
```javascript
596+
await render(hbs`<div class="container"></div>`);
597+
```
598+
591599
Returns **[Promise][66]\<void>** resolves when settled
592600

593601
### clearRender
@@ -897,6 +905,17 @@ element).
897905

898906
* `context` **TestContext** the context to setup for rendering
899907

908+
#### Examples
909+
910+
Rendering out a paragraph element containing the content 'hello', and then clearing that content via clearRender.
911+
912+
```javascript
913+
await render(hbs`<p>Hello!</p>`);
914+
assert.equal(this.element.textContent, 'Hello!', 'has rendered content');
915+
await clearRender();
916+
assert.equal(this.element.textContent, '', 'has rendered content');
917+
```
918+
900919
Returns **[Promise][66]\<RenderingTestContext>** resolves with the context that was setup
901920

902921
### getApplication
@@ -1255,23 +1274,23 @@ Returns **([Array][70]\<Warning> | [Promise][66]<[Array][70]\<Warning>>)** An ar
12551274

12561275
[54]: #getdeprecations
12571276

1258-
[55]: #examples-23
1277+
[55]: #examples-25
12591278

12601279
[56]: #getdeprecationsduringcallback
12611280

12621281
[57]: #parameters-29
12631282

1264-
[58]: #examples-24
1283+
[58]: #examples-26
12651284

12661285
[59]: #getwarnings
12671286

1268-
[60]: #examples-25
1287+
[60]: #examples-27
12691288

12701289
[61]: #getwarningsduringcallback
12711290

12721291
[62]: #parameters-30
12731292

1274-
[63]: #examples-26
1293+
[63]: #examples-28
12751294

12761295
[64]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
12771296

addon-test-support/@ember/test-helpers/setup-rendering-context.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ export interface RenderOptions {
9191
@param {Template|Component} templateOrComponent the component (or template) to render
9292
@param {RenderOptions} options options hash containing engine owner ({ owner: engineOwner })
9393
@returns {Promise<void>} resolves when settled
94+
95+
@example
96+
<caption>
97+
Render a div element with the class 'container'.
98+
</caption>
99+
await render(hbs`<div class="container"></div>`);
94100
*/
95101
export function render(
96102
templateOrComponent: TemplateFactory | ComponentInstance,
@@ -270,6 +276,16 @@ export function clearRender(): Promise<void> {
270276
@public
271277
@param {TestContext} context the context to setup for rendering
272278
@returns {Promise<RenderingTestContext>} resolves with the context that was setup
279+
280+
@example
281+
<caption>
282+
Rendering out a paragraph element containing the content 'hello', and then clearing that content via clearRender.
283+
</caption>
284+
285+
await render(hbs`<p>Hello!</p>`);
286+
assert.equal(this.element.textContent, 'Hello!', 'has rendered content');
287+
await clearRender();
288+
assert.equal(this.element.textContent, '', 'has rendered content');
273289
*/
274290
export default function setupRenderingContext(
275291
context: TestContext

0 commit comments

Comments
 (0)