我正在为仪表板组件(即延迟加载的组件)创建单元测试用例。
在仪表板组件中,我正在使用routerlink:
<div class="navbar-nav">
<a class="nav-item nav-link home" routerLink="/dashboard/home">Home</a>
<a class="nav-item nav-link profile" routerLink="/dashboard/profile">Profile</a>
<a class="nav-item nav-link logout" (click)="logout()">Logout</a>
</div>
对此的单元测试用例:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DashboardComponent, LoginComponent, ErrorComponent, RegistrationComponent, HomeComponent, ProfileComponent,
HomePageListingComponent],
imports: [
RouterTestingModule,
]
})
.compileComponents();
}));
it('should navigate to home page if clicked home navigation', fakeAsync(() => {
const router = TestBed.get(Router);
const location = TestBed.get(Location);
router.initialNavigation();
const loader = TestBed.get(NgModuleFactoryLoader);
loader.stubbedModules = {lazyModule: PrivateModule};
router.resetConfig([
{path: 'dashboard', loadChildren: 'lazyModule'},
]);
const profileLink = fixture.debugElement.query(By.css('.profile')).nativeElement;
expect(profileLink.text).toEqual('Profile');
expect(profileLink.pathname).toEqual('/dashboard/profile');
profileLink.click();
tick();
fixture.detectChanges();
expect(location.path()).toBe('/dashboard/profile');
}));
我已经检查了此question并尝试使用相同的概念,但收到此错误:
错误:未捕获(承诺):错误:找不到模块“ lazyModule”
我是否正在缺少某些东西或任何其他方法来实现这一目标。