Skip to content

Commit e28a25f

Browse files
authored
update more specs
1 parent 1baee54 commit e28a25f

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

apps/example-app/src/app/examples/09-router.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event';
44
import { DetailComponent, RootComponent, HiddenDetailComponent } from './09-router';
55

66
test('it can navigate to routes', async () => {
7+
const user = userEvent.setup();
78
await render(RootComponent, {
89
declarations: [DetailComponent, HiddenDetailComponent],
910
routes: [
@@ -25,20 +26,20 @@ test('it can navigate to routes', async () => {
2526

2627
expect(screen.queryByText(/Detail one/i)).not.toBeInTheDocument();
2728

28-
userEvent.click(screen.getByRole('link', { name: /load one/i }));
29+
await user.click(screen.getByRole('link', { name: /load one/i }));
2930
expect(await screen.findByRole('heading', { name: /Detail one/i })).toBeInTheDocument();
3031

31-
userEvent.click(screen.getByRole('link', { name: /load three/i }));
32+
await user.click(screen.getByRole('link', { name: /load three/i }));
3233
expect(screen.queryByRole('heading', { name: /Detail one/i })).not.toBeInTheDocument();
3334
expect(await screen.findByRole('heading', { name: /Detail three/i })).toBeInTheDocument();
3435

35-
userEvent.click(screen.getByRole('link', { name: /back to parent/i }));
36+
await user.click(screen.getByRole('link', { name: /back to parent/i }));
3637
expect(screen.queryByRole('heading', { name: /Detail three/i })).not.toBeInTheDocument();
3738

38-
userEvent.click(screen.getByRole('link', { name: /load two/i }));
39+
await user.click(screen.getByRole('link', { name: /load two/i }));
3940
expect(await screen.findByRole('heading', { name: /Detail two/i })).toBeInTheDocument();
4041

41-
userEvent.click(screen.getByRole('link', { name: /hidden x/i }));
42+
await user.click(screen.getByRole('link', { name: /hidden x/i }));
4243
expect(await screen.findByText(/You found the treasure!/i)).toBeInTheDocument();
4344
});
4445

apps/example-app/src/app/examples/14-async-component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { render, screen, fireEvent } from '@testing-library/angular';
33

44
import { AsyncComponent } from './14-async-component';
55

6+
// eslint-disable-next-line jest/no-disabled-tests
67
test.skip('can use fakeAsync utilities', fakeAsync(async () => {
78
await render(AsyncComponent);
89

@@ -20,6 +21,8 @@ test('can use fakeTimer utilities', async () => {
2021
await render(AsyncComponent);
2122

2223
const load = await screen.findByRole('button', { name: /load/i });
24+
25+
// userEvent not working with fake timers
2326
fireEvent.click(load);
2427

2528
jest.advanceTimersByTime(10_000);

apps/example-app/src/app/examples/15-dialog.component.spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { MatDialogModule, MatDialogRef } from '@angular/material/dialog';
2-
import { render, screen, fireEvent } from '@testing-library/angular';
2+
import { render, screen } from '@testing-library/angular';
33
import userEvent from '@testing-library/user-event';
44

55
import { DialogComponent, DialogContentComponent, DialogContentComponentModule } from './15-dialog.component';
66

77
test('dialog closes', async () => {
8+
const user = userEvent.setup();
9+
810
const closeFn = jest.fn();
911
await render(DialogContentComponent, {
1012
imports: [MatDialogModule],
@@ -19,28 +21,28 @@ test('dialog closes', async () => {
1921
});
2022

2123
const cancelButton = await screen.findByRole('button', { name: /cancel/i });
22-
userEvent.click(cancelButton);
24+
await user.click(cancelButton);
2325

2426
expect(closeFn).toHaveBeenCalledTimes(1);
2527
});
2628

2729
test('closes the dialog via the backdrop', async () => {
30+
const user = userEvent.setup();
31+
2832
await render(DialogComponent, {
2933
imports: [MatDialogModule, DialogContentComponentModule],
3034
});
3135

3236
const openDialogButton = await screen.findByRole('button', { name: /open dialog/i });
33-
userEvent.click(openDialogButton);
37+
await user.click(openDialogButton);
3438

3539
const dialogControl = await screen.findByRole('dialog');
3640
expect(dialogControl).toBeInTheDocument();
3741
const dialogTitleControl = await screen.findByRole('heading', { name: /dialog title/i });
3842
expect(dialogTitleControl).toBeInTheDocument();
3943

40-
// using fireEvent because of:
41-
// unable to click element as it has or inherits pointer-events set to "none"
42-
// eslint-disable-next-line testing-library/no-node-access, @typescript-eslint/no-non-null-assertion
43-
fireEvent.click(document.querySelector('.cdk-overlay-backdrop')!);
44+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, testing-library/no-node-access
45+
await user.click(document.querySelector('.cdk-overlay-backdrop')!);
4446

4547
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
4648

@@ -49,20 +51,22 @@ test('closes the dialog via the backdrop', async () => {
4951
});
5052

5153
test('opens and closes the dialog with buttons', async () => {
54+
const user = userEvent.setup();
55+
5256
await render(DialogComponent, {
5357
imports: [MatDialogModule, DialogContentComponentModule],
5458
});
5559

5660
const openDialogButton = await screen.findByRole('button', { name: /open dialog/i });
57-
userEvent.click(openDialogButton);
61+
await user.click(openDialogButton);
5862

5963
const dialogControl = await screen.findByRole('dialog');
6064
expect(dialogControl).toBeInTheDocument();
6165
const dialogTitleControl = await screen.findByRole('heading', { name: /dialog title/i });
6266
expect(dialogTitleControl).toBeInTheDocument();
6367

6468
const cancelButton = await screen.findByRole('button', { name: /cancel/i });
65-
userEvent.click(cancelButton);
69+
await user.click(cancelButton);
6670

6771
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
6872

apps/example-app/src/app/examples/20-test-harness.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import user from '@testing-library/user-event';
66

77
import { SnackBarComponent } from './20-test-harness';
88

9+
// eslint-disable-next-line jest/no-disabled-tests
910
test.skip('can be used with TestHarness', async () => {
1011
const view = await render(`<app-harness></app-harness>`, {
1112
imports: [SnackBarComponent],
@@ -20,6 +21,7 @@ test.skip('can be used with TestHarness', async () => {
2021
expect(await snackbarHarness.getMessage()).toMatch(/Pizza Party!!!/i);
2122
});
2223

24+
// eslint-disable-next-line jest/no-disabled-tests
2325
test.skip('can be used in combination with TestHarness', async () => {
2426
const view = await render(SnackBarComponent);
2527
const loader = TestbedHarnessEnvironment.documentRootLoader(view.fixture);

0 commit comments

Comments
 (0)