Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing angular 2单元测试无法找到调试元素_Unit Testing_Angular_Angular2 Testing - Fatal编程技术网

Unit testing angular 2单元测试无法找到调试元素

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.debugElement来拉动该元素,以确认测试是否正常工作。但是,它总是返回为NULL

测验


在查询元素调用之前,
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;