Skip to content

Commit

Permalink
DOC: API: add render helper examples
Browse files Browse the repository at this point in the history
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)
geneukum authored and chriskrycho committed Dec 15, 2022

Verified

This commit was signed with the committer’s verified signature.
chriskrycho Chris Krycho
1 parent f01ad9f commit f476a20
Showing 2 changed files with 40 additions and 5 deletions.
29 changes: 24 additions & 5 deletions API.md
Original file line number Diff line number Diff line change
@@ -311,7 +311,7 @@ keyboard.

#### Parameters

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

* `options.backwards` **[boolean][71]** indicates if the the user navigates backwards (optional, default `false`)
* `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.
* `templateOrComponent` **(Template | Component)** the component (or template) to render
* `options` **RenderOptions** options hash containing engine owner ({ owner: engineOwner })

#### Examples

Render a div element with the class 'container'.

```javascript
await render(hbs`<div class="container"></div>`);
```

Returns **[Promise][66]\<void>** resolves when settled

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

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

#### Examples

Rendering out a paragraph element containing the content 'hello', and then clearing that content via clearRender.

```javascript
await render(hbs`<p>Hello!</p>`);
assert.equal(this.element.textContent, 'Hello!', 'has rendered content');
await clearRender();
assert.equal(this.element.textContent, '', 'has rendered content');
```

Returns **[Promise][66]\<RenderingTestContext>** resolves with the context that was setup

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

[54]: #getdeprecations

[55]: #examples-22
[55]: #examples-24

[56]: #getdeprecationsduringcallback

[57]: #parameters-29

[58]: #examples-23
[58]: #examples-25

[59]: #getwarnings

[60]: #examples-24
[60]: #examples-26

[61]: #getwarningsduringcallback

[62]: #parameters-30

[63]: #examples-25
[63]: #examples-27

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

16 changes: 16 additions & 0 deletions addon-test-support/@ember/test-helpers/setup-rendering-context.ts
Original file line number Diff line number Diff line change
@@ -91,6 +91,12 @@ export interface RenderOptions {
@param {Template|Component} templateOrComponent the component (or template) to render
@param {RenderOptions} options options hash containing engine owner ({ owner: engineOwner })
@returns {Promise<void>} resolves when settled
@example
<caption>
Render a div element with the class 'container'.
</caption>
await render(hbs`<div class="container"></div>`);
*/
export function render(
templateOrComponent: TemplateFactory | ComponentInstance,
@@ -270,6 +276,16 @@ export function clearRender(): Promise<void> {
@public
@param {TestContext} context the context to setup for rendering
@returns {Promise<RenderingTestContext>} resolves with the context that was setup
@example
<caption>
Rendering out a paragraph element containing the content 'hello', and then clearing that content via clearRender.
</caption>
await render(hbs`<p>Hello!</p>`);
assert.equal(this.element.textContent, 'Hello!', 'has rendered content');
await clearRender();
assert.equal(this.element.textContent, '', 'has rendered content');
*/
export default function setupRenderingContext(
context: TestContext

0 comments on commit f476a20

Please sign in to comment.