【发布时间】:2018-06-05 15:06:20
【问题描述】:
我做了一个简单的app,它运行正常。
现在我正在尝试编写该应用程序的测试用例,因此我尝试使用routing。
stackblitz
我的路由代码是这个
主模块:
export const routes: Routes = [
{ path: '', redirectTo: '/users', pathMatch: 'full' },
];
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
UserModule,
HttpClientModule,
RouterModule.forRoot(routes)
],
功能模块:
const routes: Routes = [
{path: 'users', component: ListingComponent}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(routes)
],
declarations: [ListingComponent]
})
代码
我尝试运行我的spec,但我遇到了错误
describe('Initial navigation', () => {
it('default route redirects to home (async)', fakeAsync(() => {
router.initialNavigation(); // triggers default
fixture.detectChanges();
tick();
console.log('==================');
console.log(location.path());
// fixture.whenStable().then(() => {
expect(location.path()).toBe('/users');
// })
}));
});
【问题讨论】:
-
您是否尝试过使用
RouterTestingModule? angular.io/api/router/testing/RouterTestingModule这篇文章可能会有所帮助:stackoverflow.com/questions/39791773/… -
是的,我用的是结节
标签: javascript angular jasmine