Skip to content

Commit ca84460

Browse files
authored
update more specs
1 parent 33b0776 commit ca84460

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

apps/example-app/src/app/examples/00-single-component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { render, screen } from '@testing-library/angular';
22
import userEvent from '@testing-library/user-event';
3+
34
import { SingleComponent } from './00-single-component';
45

56
test('renders the current value and can increment and decrement', async () => {
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { render, screen, fireEvent } from '@testing-library/angular';
1+
import { render, screen } from '@testing-library/angular';
2+
import userEvent from '@testing-library/user-event';
23

34
import { NestedButtonComponent, NestedValueComponent, NestedContainerComponent } from './01-nested-component';
45

56
test('renders the current value and can increment and decrement', async () => {
7+
const user = userEvent.setup();
68
await render(NestedContainerComponent, {
79
declarations: [NestedButtonComponent, NestedValueComponent],
810
});
@@ -13,10 +15,10 @@ test('renders the current value and can increment and decrement', async () => {
1315

1416
expect(valueControl).toHaveTextContent('0');
1517

16-
fireEvent.click(incrementControl);
17-
fireEvent.click(incrementControl);
18+
await user.click(incrementControl);
19+
await user.click(incrementControl);
1820
expect(valueControl).toHaveTextContent('2');
1921

20-
fireEvent.click(decrementControl);
22+
await user.click(decrementControl);
2123
expect(valueControl).toHaveTextContent('1');
2224
});

apps/example-app/src/app/examples/02-input-output.spec.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { render, screen, fireEvent } from '@testing-library/angular';
1+
import { render, screen } from '@testing-library/angular';
2+
import userEvent from '@testing-library/user-event';
23

34
import { InputOutputComponent } from './02-input-output';
45

56
test('is possible to set input and listen for output', async () => {
7+
const user = userEvent.setup();
68
const sendValue = jest.fn();
79

810
await render(InputOutputComponent, {
@@ -22,17 +24,18 @@ test('is possible to set input and listen for output', async () => {
2224

2325
expect(valueControl).toHaveTextContent('47');
2426

25-
fireEvent.click(incrementControl);
26-
fireEvent.click(incrementControl);
27-
fireEvent.click(incrementControl);
27+
await user.click(incrementControl);
28+
await user.click(incrementControl);
29+
await user.click(incrementControl);
2830
expect(valueControl).toHaveTextContent('50');
2931

30-
fireEvent.click(sendControl);
32+
await user.click(sendControl);
3133
expect(sendValue).toHaveBeenCalledTimes(1);
3234
expect(sendValue).toHaveBeenCalledWith(50);
3335
});
3436

3537
test('is possible to set input and listen for output with the template syntax', async () => {
38+
const user = userEvent.setup();
3639
const sendSpy = jest.fn();
3740

3841
await render('<app-fixture [value]="47" (sendValue)="sendValue($event)" (clicked)="clicked()"></app-fixture>', {
@@ -48,12 +51,12 @@ test('is possible to set input and listen for output with the template syntax',
4851

4952
expect(valueControl).toHaveTextContent('47');
5053

51-
fireEvent.click(incrementControl);
52-
fireEvent.click(incrementControl);
53-
fireEvent.click(incrementControl);
54+
await user.click(incrementControl);
55+
await user.click(incrementControl);
56+
await user.click(incrementControl);
5457
expect(valueControl).toHaveTextContent('50');
5558

56-
fireEvent.click(sendControl);
59+
await user.click(sendControl);
5760
expect(sendSpy).toHaveBeenCalledTimes(1);
5861
expect(sendSpy).toHaveBeenCalledWith(50);
5962
});

apps/example-app/src/app/examples/03-forms.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event';
44
import { FormsComponent } from './03-forms';
55

66
test('is possible to fill in a form and verify error messages (with the help of jest-dom https://testing-library.com/docs/ecosystem-jest-dom)', async () => {
7+
const user = userEvent.setup();
78
await render(FormsComponent);
89

910
const nameControl = screen.getByRole('textbox', { name: /name/i });
@@ -16,19 +17,19 @@ test('is possible to fill in a form and verify error messages (with the help of
1617
expect(errors).toContainElement(screen.queryByText('color is required'));
1718

1819
expect(nameControl).toBeInvalid();
19-
userEvent.type(nameControl, 'Tim');
20-
userEvent.clear(scoreControl);
21-
userEvent.type(scoreControl, '12');
20+
await user.type(nameControl, 'Tim');
21+
await user.clear(scoreControl);
22+
await user.type(scoreControl, '12');
2223
fireEvent.blur(scoreControl);
23-
userEvent.selectOptions(colorControl, 'G');
24+
await user.selectOptions(colorControl, 'G');
2425

2526
expect(screen.queryByText('name is required')).not.toBeInTheDocument();
2627
expect(screen.getByText('score must be lesser than 10')).toBeInTheDocument();
2728
expect(screen.queryByText('color is required')).not.toBeInTheDocument();
2829

2930
expect(scoreControl).toBeInvalid();
30-
userEvent.clear(scoreControl);
31-
userEvent.type(scoreControl, '7');
31+
await user.clear(scoreControl);
32+
await user.type(scoreControl, '7');
3233
fireEvent.blur(scoreControl);
3334
expect(scoreControl).toBeValid();
3435

0 commit comments

Comments
 (0)