Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.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
Javascript 单元测试中未执行路由器事件_Javascript_Angular_Typescript_Jasmine - Fatal编程技术网

Javascript 单元测试中未执行路由器事件

Javascript 单元测试中未执行路由器事件,javascript,angular,typescript,jasmine,Javascript,Angular,Typescript,Jasmine,我正在尝试测试我的路由器。事件,但这些事件没有触发,我不确定原因。我试过了,但运气不好 以下是我的测试设置: description('AppComponent',()=>{ let组件:AppComponent; let fixture:component fixture您还必须确保运行更改检测: /**/ fixture.detectChanges(); (TestBed.inject(Router).events作为主题)。next(event); 您是否也尝试过在事件之后使用组件.det

我正在尝试测试我的
路由器。事件
,但这些事件没有触发,我不确定原因。我试过了,但运气不好

以下是我的测试设置:

description('AppComponent',()=>{
let组件:AppComponent;

let fixture:component fixture

您还必须确保运行更改检测:

/**/
fixture.detectChanges();
(TestBed.inject(Router).events作为主题)。next(event);

您是否也尝试过在
事件之后使用
组件.detectChanges()
下一步()
?我还没有尝试过。你不需要在异步模式下进行此操作,然后进行勾选和刷新以获得订阅来解决问题吗?你确定
elementApps
在当时不是空数组,因此它不会执行吗?@AliF50这看起来是问题所在,
elementApps
@ViewChildren()
,并在
.next()
之前调用
fixture.detectChanges()
使其工作。测试后,修复方法是将其添加到
.next()
之前,因为它在模板中找不到元素。@GetOffMyLawn有意义。我已更新了答案。谢谢!