Angular 7: Как создать модульный тест для ленивых Loaded маршрутизаторов - PullRequest
1 голос
/ 04 июля 2019

Я создаю модульные тесты для компонента Dashboard, то есть для лениво загруженного компонента.

В компоненте Dashboard я использую 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');

  }));

Я проверил этот вопрос и попытался использовать ту же концепцию, но получаю эту ошибку:

Ошибка: Uncaught (в обещании): Ошибка: Невозможно найти модуль 'lazyModule'

Я что-то упускаю или любой другой подход для достижения этой цели.

enter image description here

...