Unit testing angular 2单元测试无法找到调试元素
我试图在我的组件上运行单元测试,该组件是路由器的输出。我已经对组件使用的路由器和服务进行了存根,我正在尝试使用fixture.debugElement来拉动该元素,以确认测试是否正常工作。但是,它总是返回为NULL 测验Unit testing angular 2单元测试无法找到调试元素,unit-testing,angular,angular2-testing,Unit Testing,Angular,Angular2 Testing,我试图在我的组件上运行单元测试,该组件是路由器的输出。我已经对组件使用的路由器和服务进行了存根,我正在尝试使用fixture.debugElement来拉动该元素,以确认测试是否正常工作。但是,它总是返回为NULL 测验 在查询元素调用之前,fixture.detectChanges fixture = TestBed.createComponent(HeroesComponent); comp = fixture.componentInstance; //call detect change
在查询元素调用之前,
fixture.detectChanges
fixture = TestBed.createComponent(HeroesComponent);
comp = fixture.componentInstance;
//call detect changes here
fixture.detectChanges();
de = fixture.debugElement.query(By.css('*'));
console.log(de);
el = de.nativeElement;
什么是空的?
de
?是de
为空在运行查询之前组件是否稳定?尝试运行fixture.isStable()并发布结果。
export class StubRouter {
navigateByUrl(url: string) { return url; }
}
fixture = TestBed.createComponent(HeroesComponent);
comp = fixture.componentInstance;
//call detect changes here
fixture.detectChanges();
de = fixture.debugElement.query(By.css('*'));
console.log(de);
el = de.nativeElement;