-
Notifications
You must be signed in to change notification settings - Fork 91
Bug with location.back() #280
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
Comments
Hi, this seems like to be a bug. Since it's the first time that I've encountered the If you have any ideas, feel free to suggest them. |
@timdeschryver, I can write the test, are you sure you want me to put test in? As per fix, no no no... I don't understand how Angular or Angular Test Framework works, I definitely don't want to mess with it. Thank you for the help. I'll make PR (with test) in next couple of days. P.S: developing angular app is just a hobby, I don't work with it on daily basis. I just spend an hour or so on weekends. |
Cloned project and tests are failing before I even started... |
@meirka Oh.. yikes those failing tests shouldn't happen 😅 |
@timdeschryver I would like to add a test. I emailed you test error details. I figured to take test issues off the thread. |
@meirka Oh, I think that you mailed it to a no-reply address... perhaps that I should use my "real" e-mail address here 😅 I'll try to run the tests locally and see if I can reproduce the error. |
@meirka I can confirm that I also have the errors, seems like some newer version TL is causing this. |
@timdeschryver Yeah, tests are good now. Give me few days, let me try to workout tests |
@timdeschryver It doesn't want to click on 'navigate back' and I don't understand why. |
@meirka try this. The following always is truthy because
The version with the declarations: @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', async () => {
// await render(MainComponent, {imports: [AppRoutingModule, RouterTestingModule]});
const subject = await render(MainComponent, { imports: [AppRoutingModule, RouterTestingModule] });
await subject.navigate('/');
const router = TestBed.inject(Router);
router.initialNavigation();
expect(await screen.findByText('Navigate')).toBeTruthy();
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', { selector: 'button' }));
expect(await screen.findByText('first page')).toBeTruthy();
}); |
Thank you! |
@timdeschryver PR is up - made changes, verified that test is failing (due to the bug). |
🎉 This issue has been resolved in version 11.0.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hello, I believe I found a bug, where angular testing library doesn't seem to handle
location.back()
scenario.I have prepared simple project with very basic navigation, specs with TestBed and with Angular Testing Library. In case of TestBed navigation works correctly, but with Angular Testing Library it does not.
https://github.com/meirka/angular-unit-test-navigation
I have similar test in my side project and i'm experiencing the same issue.
Please advise.
Thank you.
The text was updated successfully, but these errors were encountered: