Skip to content
Merged
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
57 changes: 57 additions & 0 deletions apps/example-app-karma/src/app/issues/issue-491.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { render, screen, waitForElementToBeRemoved } from '@testing-library/angular';
import userEvent from '@testing-library/user-event';

it('test click event with router.navigate', async () => {
const user = userEvent.setup();
await render(`<router-outlet></router-outlet>`, {
routes: [
{
path: '',
component: LoginComponent,
},
{
path: 'logged-in',
component: LoggedInComponent,
},
],
});

expect(await screen.findByRole('heading', { name: 'Login' })).toBeVisible();
expect(screen.getByRole('button', { name: 'submit' })).toBeInTheDocument();

const email = screen.getByRole('textbox', { name: 'email' });
const password = screen.getByLabelText('password');

await user.type(email, '[email protected]');
await user.type(password, 'with_valid_password');

expect(screen.getByRole('button', { name: 'submit' })).toBeEnabled();

await user.click(screen.getByRole('button', { name: 'submit' }));

await waitForElementToBeRemoved(() => screen.queryByRole('heading', { name: 'Login' }));

expect(await screen.findByRole('heading', { name: 'Logged In' })).toBeVisible();
});

@Component({
template: `
<h1>Login</h1>
<button type="submit" (click)="onSubmit()">submit</button>
<input type="email" aria-label="email" />
<input type="password" aria-label="password" />
`,
})
class LoginComponent {
constructor(private router: Router) {}
onSubmit(): void {
this.router.navigate(['logged-in']);
}
}

@Component({
template: ` <h1>Logged In</h1> `,
})
class LoggedInComponent {}