-
Notifications
You must be signed in to change notification settings - Fork 93
Test case for the issue 280 #284
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {Component, NgModule} from '@angular/core'; | ||
import {render, screen} from '../../src/public_api'; | ||
import {RouterModule, Routes} from "@angular/router"; | ||
import {RouterTestingModule} from "@angular/router/testing"; | ||
import {click} from "@testing-library/user-event/dist/click"; | ||
meirka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import {Location} from "@angular/common"; | ||
|
||
@Component({ | ||
template: `<div>Navigate</div> <router-outlet></router-outlet>`, | ||
}) | ||
class MainComponent {} | ||
|
||
@Component({ | ||
template: `<div>first page</div><a routerLink="/second">go to second</a>` | ||
}) | ||
class FirstComponent {} | ||
|
||
@Component({ | ||
template: `<div>second page</div><button (click)="goBack()">navigate back</button>` | ||
}) | ||
class SecondComponent { | ||
constructor(private location: Location) { } | ||
goBack() {this.location.back();} | ||
} | ||
|
||
const routes: Routes = [ | ||
{path: '', redirectTo: '/first', pathMatch: 'full'}, | ||
{path: 'first', component: FirstComponent}, | ||
{path: 'second', component: SecondComponent} | ||
]; | ||
|
||
@NgModule({ | ||
declarations: [FirstComponent, SecondComponent], | ||
imports: [RouterModule.forRoot(routes)], | ||
exports: [RouterModule] | ||
}) | ||
class AppRoutingModule {} | ||
|
||
|
||
test('navigate to second page and back', async () => { | ||
const subject = await render(MainComponent, {imports: [AppRoutingModule, RouterTestingModule]}); | ||
await subject.navigate('/'); | ||
|
||
expect(await screen.findByText('Navigate')).toBeTruthy(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left extra expects in place, showing that there is successful navigation to second page. Thank you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine, thanks! |
||
expect(await screen.findByText('first page')).toBeTruthy(); | ||
|
||
click(await screen.findByText('go to second')); | ||
|
||
expect(await screen.findByText('second page')).toBeTruthy(); | ||
expect(await screen.findByText('navigate back')).toBeTruthy(); | ||
|
||
click(await screen.findByText('navigate back')); | ||
|
||
expect(await screen.findByText('first page')).toBeTruthy(); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.