Angular 如何测试在角6+;

Angular 如何测试在角6+;,angular,karma-jasmine,Angular,Karma Jasmine,这是我的应用程序组件 <app-header></app-header> <router-outlet></router-outlet> <app-footer></app-footer> 在header组件中,我有一个变量“loadedComponent”,它告诉我加载了哪个组件 this.router.events .pipe(filter(event => event instanceof Navi

这是我的应用程序组件

<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>
在header组件中,我有一个变量“loadedComponent”,它告诉我加载了哪个组件

this.router.events
      .pipe(filter(event => event instanceof NavigationEnd))
      .subscribe(() => {
        this.loadedComponent = this.activatedRoute.firstChild.component;
      });
getComponent(): boolean{
   return this.loadedComponent === HomeComponent
}
我调用一个函数getComponent,如果加载了一个特定的组件,它将返回布尔值

this.router.events
      .pipe(filter(event => event instanceof NavigationEnd))
      .subscribe(() => {
        this.loadedComponent = this.activatedRoute.firstChild.component;
      });
getComponent(): boolean{
   return this.loadedComponent === HomeComponent
}
我想用jasmine在我的单元测试用例中测试这个函数

这是我的套房-

it('should test someComponentLoaded', async( () =>{
      fixture = TestBed.createComponent(HeaderComponent);
      component = fixture.componentInstance;
      fixture.detectChanges();
      fixture.componentInstance.getComponent();
      console.log("test loaded component", fixture.componentInstance.getComponent());
    })
  )
问题是console.log总是给我false,即使条件为true 我在这里做错了什么。如果有人能告诉我正确的解决方案,我真的很感激?提前谢谢