Skip to content

Commit 2570111

Browse files
docs(angular): update to latest version (#450)
1 parent fc2c2ea commit 2570111

File tree

2 files changed

+54
-28
lines changed

2 files changed

+54
-28
lines changed

docs/angular-testing-library/api.md

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ well as these methods:
99

1010
- [`render`](<(#render)>)
1111

12+
Some of the `DOM Testing Library` re-exports are patched to work easier with
13+
Angular:
14+
15+
- The events on `fireEvent` automatically invoke a change detection cycle after
16+
the event has been fired
17+
- The `findBy` queries automatically invoke a change detection cycle before the
18+
query is invoked function
19+
- The `waitFor` functions automatically invoke a change detection cycle before
20+
invoking the callback function
21+
1222
## `render`
1323

1424
```typescript
@@ -189,6 +199,20 @@ const component = await render(AppComponent, {
189199
})
190200
```
191201

202+
### `removeAngularAttributes`
203+
204+
Removes the Angular attributes (ng-version, and root-id) from the fixture.
205+
206+
**default** : `false`
207+
208+
**example**:
209+
210+
```typescript
211+
const component = await render(AppComponent, {
212+
removeAngularAttributes: true,
213+
})
214+
```
215+
192216
## Directive RenderOptions
193217

194218
To test a directive, the render API is a bit different. The API has the same
@@ -244,11 +268,11 @@ component.debug(component.getByRole('alert'))
244268

245269
### `rerender`
246270

247-
Re-render the same component with different props.
248-
Will call `detectChanges` after props has been updated.
271+
Re-render the same component with different props. Will call `detectChanges`
272+
after props has been updated.
249273

250274
```typescript
251-
const component = await render(Counter, { componentProperties: { count: 4 }})
275+
const component = await render(Counter, { componentProperties: { count: 4 } })
252276
253277
expect(component.getByTestId('count-value').textContent).toBe('4')
254278
@@ -258,11 +282,11 @@ expect(component.getByTestId('count-value').textContent).toBe('7')
258282

259283
### `fireEvent.***`
260284

261-
The second most important feature of `render` is that the events from
262-
[DOM Testing Library](https://testing-library.com/docs/dom-testing-library) are
263-
automatically bound to the Angular Component. This to ensure that the Angular
264-
change detection has been run by calling `detectChanges` after an event has been
265-
fired.
285+
The `fireEvents` re-exported from
286+
[DOM Testing Library](https://testing-library.com/docs/dom-testing-library) that
287+
are automatically bound to the Angular Component. This to ensure that the
288+
Angular change detection has been run by invoking `detectChanges` after an event
289+
has been fired.
266290

267291
See
268292
[Firing Events](https://testing-library.com/docs/dom-testing-library/api-events)
@@ -281,6 +305,12 @@ component.change(component.getByLabelText('Username'), {
281305
component.click(component.getByText('Login'))
282306
```
283307

308+
### `debugElement`
309+
310+
The Angular `DebugElement` of the component.
311+
312+
For more info see the [Angular docs](https://angular.io/api/core/DebugElement).
313+
284314
### `fixture`
285315

286316
The Angular `ComponentFixture` of the component.
@@ -355,23 +385,19 @@ component.type(component.getByLabelText('Username'), 'Tim')
355385
component.type(component.getByLabelText('Username'), 'Tim', { delay: 250 })
356386
```
357387

358-
### `waitForDomChange`
359-
360-
Wait for the DOM to change.
361-
For more info see the [DOM Testing Library docs](https://testing-library.com/docs/dom-testing-library/api-async#waitfordomchange).
362-
363-
This function will also call `detectChanges` repeatably to update the DOM, is helpful to test async functionality.
364-
365-
### `waitForElement`
388+
### `waitFor`
366389

367-
Wait for DOM elements to appear, disappear, or change.
368-
For more info see the [DOM Testing Library docs](https://testing-library.com/docs/dom-testing-library/api-async#waitforelement).
390+
When in need to wait for any period of time you can use waitFor, to wait for
391+
your expectations to pass. For more info see the
392+
[DOM Testing Library docs](https://testing-library.com/docs/dom-testing-library/api-async#waitFor).
369393

370-
This function will also call `detectChanges` repeatably to update the DOM, is helpful to test async functionality.
394+
This function will also call `detectChanges` repeatably to update the DOM, which
395+
is helpful to test async functionalities.
371396

372397
### `waitForElementToBeRemoved`
373398

374-
Wait for the removal of element(s) from the DOM.
375-
For more info see the [DOM Testing Library docs](https://testing-library.com/docs/dom-testing-library/api-async#waitforelementtoberemoved).
399+
Wait for the removal of element(s) from the DOM. For more info see the
400+
[DOM Testing Library docs](https://testing-library.com/docs/dom-testing-library/api-async#waitforelementtoberemoved).
376401

377-
This function will also call `detectChanges` repeatably to update the DOM, is helpful to test async functionality.
402+
This function will also call `detectChanges` repeatably to update the DOM, which
403+
is helpful to test async functionalities.

docs/angular-testing-library/examples.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,26 @@ export class CounterComponent {
3535
counter.component.spec.ts
3636

3737
```typescript
38-
import { render } from '@testing-library/angular'
38+
import { render, screen, fireEvent } from '@testing-library/angular'
3939
import { CounterComponent } from './counter.component.ts'
4040

4141
describe('Counter', () => {
4242
test('should render counter', async () => {
43-
const { getByText } = await render(CounterComponent, {
43+
await render(CounterComponent, {
4444
componentProperties: { counter: 5 },
4545
})
4646

47-
expect(getByText('Current Count: 5'))
47+
expect(screen.getByText('Current Count: 5'))
4848
})
4949

5050
test('should increment the counter on click', async () => {
51-
const { getByText, click } = await render(CounterComponent, {
51+
await render(CounterComponent, {
5252
componentProperties: { counter: 5 },
5353
})
5454

55-
click(getByText('+'))
55+
fireEvent.click(screen.getByText('+'))
5656

57-
expect(getByText('Current Count: 6'))
57+
expect(screen.getByText('Current Count: 6'))
5858
})
5959
})
6060
```

0 commit comments

Comments
 (0)