Skip to content

Commit f476a20

Browse files
geneukumchriskrycho
authored andcommittedDec 15, 2022
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) (cherry picked from commit 0dfb1dc)
1 parent f01ad9f commit f476a20

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed
 

‎API.md

+24-5
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ keyboard.
311311

312312
#### Parameters
313313

314-
* `options` **[Object][72]?** optional tab behaviors (optional, default `{}`)
314+
* `options` **[Object][72]?** optional tab behaviors
315315

316316
* `options.backwards` **[boolean][71]** indicates if the the user navigates backwards (optional, default `false`)
317317
* `options.unRestrainTabIndex` **[boolean][71]** indicates if tabbing should throw an error when tabindex is greater than 0 (optional, default `false`)
@@ -574,6 +574,14 @@ Renders the provided template and appends it to the DOM.
574574
* `templateOrComponent` **(Template | Component)** the component (or template) to render
575575
* `options` **RenderOptions** options hash containing engine owner ({ owner: engineOwner })
576576

577+
#### Examples
578+
579+
Render a div element with the class 'container'.
580+
581+
```javascript
582+
await render(hbs`<div class="container"></div>`);
583+
```
584+
577585
Returns **[Promise][66]\<void>** resolves when settled
578586

579587
### clearRender
@@ -883,6 +891,17 @@ element).
883891

884892
* `context` **TestContext** the context to setup for rendering
885893

894+
#### Examples
895+
896+
Rendering out a paragraph element containing the content 'hello', and then clearing that content via clearRender.
897+
898+
```javascript
899+
await render(hbs`<p>Hello!</p>`);
900+
assert.equal(this.element.textContent, 'Hello!', 'has rendered content');
901+
await clearRender();
902+
assert.equal(this.element.textContent, '', 'has rendered content');
903+
```
904+
886905
Returns **[Promise][66]\<RenderingTestContext>** resolves with the context that was setup
887906

888907
### getApplication
@@ -1241,23 +1260,23 @@ Returns **([Array][70]\<Warning> | [Promise][66]<[Array][70]\<Warning>>)** An ar
12411260

12421261
[54]: #getdeprecations
12431262

1244-
[55]: #examples-22
1263+
[55]: #examples-24
12451264

12461265
[56]: #getdeprecationsduringcallback
12471266

12481267
[57]: #parameters-29
12491268

1250-
[58]: #examples-23
1269+
[58]: #examples-25
12511270

12521271
[59]: #getwarnings
12531272

1254-
[60]: #examples-24
1273+
[60]: #examples-26
12551274

12561275
[61]: #getwarningsduringcallback
12571276

12581277
[62]: #parameters-30
12591278

1260-
[63]: #examples-25
1279+
[63]: #examples-27
12611280

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

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

+16
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)
Please sign in to comment.