Skip to content

Commit a709ae5

Browse files
test: add test case for #437 (#438)
Closes #437
1 parent f78be95 commit a709ae5

File tree

2 files changed

+64
-9
lines changed

2 files changed

+64
-9
lines changed

projects/testing-library/tests/issues/issue-435.spec.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ class DemoComponent {
2626
constructor(@Inject(DemoService) public demoService: DemoService) {}
2727
}
2828

29-
// Test
30-
describe('DemoComponent', () => {
31-
it('should render button', async () => {
32-
await render(DemoComponent);
29+
test('issue #435', async () => {
30+
await render(DemoComponent);
3331

34-
const button = screen.getByRole('button', {
35-
name: /Click me/,
36-
});
37-
38-
expect(button).toBeVisible();
32+
const button = screen.getByRole('button', {
33+
name: /Click me/,
3934
});
35+
36+
expect(button).toBeVisible();
4037
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import userEvent from '@testing-library/user-event';
2+
import { screen, render } from '../../src/public_api';
3+
import { MatSidenavModule } from '@angular/material/sidenav';
4+
5+
afterEach(() => {
6+
jest.useRealTimers();
7+
});
8+
9+
test('issue #437', async () => {
10+
const user = userEvent.setup();
11+
await render(
12+
`
13+
<ng-container>
14+
<mat-sidenav-container>
15+
<mat-sidenav [opened]="true" position="end" mode="over" role="complementary">
16+
<button data-testid="test-button">test</button>
17+
</mat-sidenav>
18+
<mat-sidenav-content>
19+
<div></div>
20+
</mat-sidenav-content>
21+
</mat-sidenav-container>
22+
</ng-container>
23+
`,
24+
{ imports: [MatSidenavModule] },
25+
);
26+
27+
// eslint-disable-next-line testing-library/prefer-explicit-assert
28+
await screen.findByTestId('test-button');
29+
30+
await user.click(screen.getByTestId('test-button'));
31+
});
32+
33+
test('issue #437 with fakeTimers', async () => {
34+
jest.useFakeTimers();
35+
const user = userEvent.setup({
36+
advanceTimers: jest.advanceTimersByTime,
37+
});
38+
await render(
39+
`
40+
<ng-container>
41+
<mat-sidenav-container>
42+
<mat-sidenav [opened]="true" position="end" mode="over" role="complementary">
43+
<button data-testid="test-button">test</button>
44+
</mat-sidenav>
45+
<mat-sidenav-content>
46+
<div></div>
47+
</mat-sidenav-content>
48+
</mat-sidenav-container>
49+
</ng-container>
50+
`,
51+
{ imports: [MatSidenavModule] },
52+
);
53+
54+
// eslint-disable-next-line testing-library/prefer-explicit-assert
55+
await screen.findByTestId('test-button');
56+
57+
await user.click(screen.getByTestId('test-button'));
58+
});

0 commit comments

Comments
 (0)