Skip to content

Commit

Permalink
test: add test case for #437 (#438)
Browse files Browse the repository at this point in the history
Closes #437
  • Loading branch information
timdeschryver committed Feb 26, 2024
1 parent f78be95 commit a709ae5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
15 changes: 6 additions & 9 deletions projects/testing-library/tests/issues/issue-435.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ class DemoComponent {
constructor(@Inject(DemoService) public demoService: DemoService) {}
}

// Test
describe('DemoComponent', () => {
it('should render button', async () => {
await render(DemoComponent);
test('issue #435', async () => {
await render(DemoComponent);

const button = screen.getByRole('button', {
name: /Click me/,
});

expect(button).toBeVisible();
const button = screen.getByRole('button', {
name: /Click me/,
});

expect(button).toBeVisible();
});
58 changes: 58 additions & 0 deletions projects/testing-library/tests/issues/issue-437.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import userEvent from '@testing-library/user-event';
import { screen, render } from '../../src/public_api';
import { MatSidenavModule } from '@angular/material/sidenav';

afterEach(() => {
jest.useRealTimers();
});

test('issue #437', async () => {
const user = userEvent.setup();
await render(
`
<ng-container>
<mat-sidenav-container>
<mat-sidenav [opened]="true" position="end" mode="over" role="complementary">
<button data-testid="test-button">test</button>
</mat-sidenav>
<mat-sidenav-content>
<div></div>
</mat-sidenav-content>
</mat-sidenav-container>
</ng-container>
`,
{ imports: [MatSidenavModule] },
);

// eslint-disable-next-line testing-library/prefer-explicit-assert
await screen.findByTestId('test-button');

await user.click(screen.getByTestId('test-button'));
});

test('issue #437 with fakeTimers', async () => {
jest.useFakeTimers();
const user = userEvent.setup({
advanceTimers: jest.advanceTimersByTime,
});
await render(
`
<ng-container>
<mat-sidenav-container>
<mat-sidenav [opened]="true" position="end" mode="over" role="complementary">
<button data-testid="test-button">test</button>
</mat-sidenav>
<mat-sidenav-content>
<div></div>
</mat-sidenav-content>
</mat-sidenav-container>
</ng-container>
`,
{ imports: [MatSidenavModule] },
);

// eslint-disable-next-line testing-library/prefer-explicit-assert
await screen.findByTestId('test-button');

await user.click(screen.getByTestId('test-button'));
});

0 comments on commit a709ae5

Please sign in to comment.