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.
  • Loading branch information
geneukum committed Oct 24, 2022
1 parent fa068a0 commit fb7d293
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
27 changes: 23 additions & 4 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,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
Expand Down Expand Up @@ -897,6 +905,17 @@ element).

* `context` **[Object][72]** 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]<[Object][72]>** resolves with the context that was setup

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

[54]: #getdeprecations

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

[56]: #getdeprecationsduringcallback

[57]: #parameters-29

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

[59]: #getwarnings

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

[61]: #getwarningsduringcallback

[62]: #parameters-30

[63]: #examples-26
[63]: #examples-28

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

Expand Down
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
Expand Up @@ -93,6 +93,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,
Expand Down Expand Up @@ -265,6 +271,16 @@ export function clearRender(): Promise<void> {
@public
@param {Object} context the context to setup for rendering
@returns {Promise<Object>} 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
Expand Down

0 comments on commit fb7d293

Please sign in to comment.