Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for routing and render helper examples #1289

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ Find all of the elements matching '.my-selector'.
findAll('.my-selector');
```

Returns **[Element][65]** matched element or null
Returns **([Element][65] | null)** matched element or null

### findAll

Expand Down Expand Up @@ -551,6 +551,20 @@ Navigate the application to the provided URL.
* `url` **[string][64]** The URL to visit (e.g. `/posts`)
* `options` **[object][72]** app boot options

#### Examples

Visiting the route for post 1.

```javascript
await visit('/posts/1');
```

Visiting the route for post 1 while also providing the `rootElement` app boot option.

```javascript
await visit('/', { rootElement: '#container' });
```

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

### currentRouteName
Expand All @@ -574,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 @@ -883,6 +905,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
Expand Down Expand Up @@ -1241,23 +1274,23 @@ Returns **([Array][70]\<Warning> | [Promise][66]<[Array][70]\<Warning>>)** An ar

[54]: #getdeprecations

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

[56]: #getdeprecationsduringcallback

[57]: #parameters-29

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

[59]: #getwarnings

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

[61]: #getwarningsduringcallback

[62]: #parameters-30

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ export function setupRouterSettlednessTracking() {
@param {string} url The URL to visit (e.g. `/posts`)
@param {object} options app boot options
@returns {Promise<void>} resolves when settled

@example
<caption>
Visiting the route for post 1.
</caption>
await visit('/posts/1');

@example
<caption>
Visiting the route for post 1 while also providing the `rootElement` app boot option.
</caption>
await visit('/', { rootElement: '#container' });
*/
export function visit(
url: 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 @@ -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,
Expand Down Expand Up @@ -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
Expand Down