Skip to content

test: add test case for #437 #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
});