Skip to content

Commit c565dbc

Browse files
committed
add new Angular API properties
1 parent e31e7b0 commit c565dbc

File tree

1 file changed

+101
-61
lines changed
  • docs/angular-testing-library

1 file changed

+101
-61
lines changed

docs/angular-testing-library/api.mdx

Lines changed: 101 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -76,62 +76,6 @@ export async function render<WrapperType = WrapperComponent>(
7676

7777
## Component RenderOptions
7878

79-
### ~~`componentInputs`~~ (deprecated)
80-
81-
An object to set `@Input` properties of the component. Uses `setInput` to set
82-
the input property. Throws if the component property is not annotated with the
83-
`@Input` attribute.
84-
85-
**default** : `{}`
86-
87-
**example**:
88-
89-
```typescript
90-
await render(AppComponent, {
91-
componentInputs: {
92-
counterValue: 10,
93-
},
94-
})
95-
```
96-
97-
### ~~`componentOutputs`~~ (deprecated)
98-
99-
An object to set `@Output` properties of the component.
100-
101-
**default** : `{}`
102-
103-
**example**:
104-
105-
```typescript
106-
await render(AppComponent, {
107-
componentOutputs: {
108-
clicked: (value) => { ... }
109-
}
110-
})
111-
```
112-
113-
### ~~`componentProperties`~~ (deprecated)
114-
115-
An object to set `@Input` and `@Output` properties of the component. Doesn't
116-
have a fine-grained control as `componentInputs` and `componentOutputs`.
117-
118-
**default** : `{}`
119-
120-
**example**:
121-
122-
```typescript
123-
await render(AppComponent, {
124-
componentProperties: {
125-
// an input
126-
counterValue: 10,
127-
// an output
128-
send: (value) => { ... }
129-
// a public property
130-
name: 'Tim'
131-
}
132-
})
133-
```
134-
13579
### `declarations`
13680

13781
A collection of components, directives and pipes needed to render the component.
@@ -157,7 +101,8 @@ Set the defer blocks behavior.
157101
For more info see the
158102
[Angular docs](https://angular.io/api/core/testing/DeferBlockBehavior)
159103

160-
**default** : `undefined` (uses `DeferBlockBehavior.Manual`, which is different from the Angular default of `DeferBlockBehavior.Playthrough`)
104+
**default** : `undefined` (uses `DeferBlockBehavior.Manual`, which is different
105+
from the Angular default of `DeferBlockBehavior.Playthrough`)
161106

162107
**example**:
163108

@@ -405,6 +350,43 @@ await render(AppComponent, {
405350

406351
## `RenderResult`
407352

353+
### `inputs`
354+
355+
An object to set `@Input` or `input()` properties of the component.
356+
357+
**default** : `{}`
358+
359+
```typescript
360+
await render(AppComponent, {
361+
inputs: {
362+
counterValue: 10,
363+
// explicitly define aliases using `aliasedInput`
364+
...aliasedInput('someAlias', 'someValue'),
365+
},
366+
})
367+
```
368+
369+
### `on`
370+
371+
An object with callbacks to subscribe to `EventEmitters` and `Observables` of
372+
the component.
373+
374+
**default** : `{}`
375+
376+
```ts
377+
// using a manual callback
378+
const sendValue = (value) => { ... }
379+
// using a (jest) spy
380+
const sendValueSpy = jest.fn()
381+
382+
await render(AppComponent, {
383+
on: {
384+
send: (value) => sendValue(value),
385+
send: sendValueSpy
386+
}
387+
})
388+
```
389+
408390
### `container`
409391

410392
The containing DOM node of your rendered Angular Component. This is a regular
@@ -430,13 +412,15 @@ properties that are not defined are cleared.
430412

431413
```typescript
432414
const {rerender} = await render(Counter, {
433-
componentInputs: {count: 4, name: 'Sarah'},
415+
inputs: {count: 4, name: 'Sarah'},
434416
})
435417
436418
expect(screen.getByTestId('count-value').textContent).toBe('4')
437419
expect(screen.getByTestId('name-value').textContent).toBe('Sarah')
438420
439-
await rerender({componentInputs: {count: 7}})
421+
await rerender({
422+
inputs: {count: 7}
423+
})
440424
441425
// count is updated to 7
442426
expect(screen.getByTestId('count-value').textContent).toBe('7')
@@ -449,13 +433,13 @@ input properties that aren't provided won't be cleared.
449433

450434
```typescript
451435
const {rerender} = await render(Counter, {
452-
componentInputs: {count: 4, name: 'Sarah'},
436+
inputs: {count: 4, name: 'Sarah'},
453437
})
454438
455439
expect(screen.getByTestId('count-value').textContent).toBe('4')
456440
expect(screen.getByTestId('name-value').textContent).toBe('Sarah')
457441
458-
await rerender({componentInputs: {count: 7}, partialUpdate: true})
442+
await rerender({inputs: {count: 7}, partialUpdate: true})
459443
460444
// count is updated to 7
461445
expect(screen.getByTestId('count-value').textContent).toBe('7')
@@ -546,3 +530,59 @@ expect(screen.getByText(/loading/i)).toBeInTheDocument()
546530
await renderDeferBlock(DeferBlockState.Complete)
547531
expect(screen.getByText(/completed/i)).toBeInTheDocument()
548532
```
533+
534+
### ~~`componentInputs`~~ (deprecated)
535+
536+
An object to set `@Input` properties of the component. Uses `setInput` to set
537+
the input property. Throws if the component property is not annotated with the
538+
`@Input` attribute.
539+
540+
**default** : `{}`
541+
542+
**example**:
543+
544+
```typescript
545+
await render(AppComponent, {
546+
componentInputs: {
547+
counterValue: 10,
548+
},
549+
})
550+
```
551+
552+
### ~~`componentOutputs`~~ (deprecated)
553+
554+
An object to set `@Output` properties of the component.
555+
556+
**default** : `{}`
557+
558+
**example**:
559+
560+
```typescript
561+
await render(AppComponent, {
562+
componentOutputs: {
563+
clicked: (value) => { ... }
564+
}
565+
})
566+
```
567+
568+
### ~~`componentProperties`~~ (deprecated)
569+
570+
An object to set `@Input` and `@Output` properties of the component. Doesn't
571+
have a fine-grained control as `inputs` and `on`.
572+
573+
**default** : `{}`
574+
575+
**example**:
576+
577+
```typescript
578+
await render(AppComponent, {
579+
componentProperties: {
580+
// an input
581+
counterValue: 10,
582+
// an output
583+
send: (value) => { ... }
584+
// a public property
585+
name: 'Tim'
586+
}
587+
})
588+
```

0 commit comments

Comments
 (0)