Skip to content

Commit f2aac87

Browse files
authored
Merge pull request #1289 from emberjs/more-docs-fixes
Add docs for routing and render helper examples
2 parents 87dfbf4 + 0dfb1dc commit f2aac87

3 files changed

Lines changed: 66 additions & 5 deletions

File tree

API.md

Lines changed: 38 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

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

554+
#### Examples
555+
556+
Visiting the route for post 1.
557+
558+
```javascript
559+
await visit('/posts/1');
560+
```
561+
562+
Visiting the route for post 1 while also providing the `rootElement` app boot option.
563+
564+
```javascript
565+
await visit('/', { rootElement: '#container' });
566+
```
567+
554568
Returns **[Promise][66]\<void>** resolves when settled
555569

556570
### currentRouteName
@@ -574,6 +588,14 @@ Renders the provided template and appends it to the DOM.
574588
* `templateOrComponent` **(Template | Component)** the component (or template) to render
575589
* `options` **RenderOptions** options hash containing engine owner ({ owner: engineOwner })
576590

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+
577599
Returns **[Promise][66]\<void>** resolves when settled
578600

579601
### clearRender
@@ -883,6 +905,17 @@ element).
883905

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

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+
886919
Returns **[Promise][66]\<RenderingTestContext>** resolves with the context that was setup
887920

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

12421275
[54]: #getdeprecations
12431276

1244-
[55]: #examples-22
1277+
[55]: #examples-25
12451278

12461279
[56]: #getdeprecationsduringcallback
12471280

12481281
[57]: #parameters-29
12491282

1250-
[58]: #examples-23
1283+
[58]: #examples-26
12511284

12521285
[59]: #getwarnings
12531286

1254-
[60]: #examples-24
1287+
[60]: #examples-27
12551288

12561289
[61]: #getwarningsduringcallback
12571290

12581291
[62]: #parameters-30
12591292

1260-
[63]: #examples-25
1293+
[63]: #examples-28
12611294

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

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ export function setupRouterSettlednessTracking() {
130130
@param {string} url The URL to visit (e.g. `/posts`)
131131
@param {object} options app boot options
132132
@returns {Promise<void>} resolves when settled
133+
134+
@example
135+
<caption>
136+
Visiting the route for post 1.
137+
</caption>
138+
await visit('/posts/1');
139+
140+
@example
141+
<caption>
142+
Visiting the route for post 1 while also providing the `rootElement` app boot option.
143+
</caption>
144+
await visit('/', { rootElement: '#container' });
133145
*/
134146
export function visit(
135147
url: string,

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)