如何在Angular测试中等待生命周期挂钩

时间:2019-04-22 17:17:04

标签: angular typescript angular-test

Angular的组件固定装置提供了一个方便的方法,称为whenStable()。它不特定于任何特定的异步事件。我想要一种工作原理类似于检测OnInitAfterViewInitAfterContentInit何时运行的方法。

我可以直接通过component.ngOnInit()调用它们,但是我不想测试生命周期挂钩中的逻辑,我希望框架调用它的后果(即绑定可用,模板已加载)等)。

我想要这样的东西:

it('should have template ready', async(async() => {
    await fixture.afterViewInit();

    // ... child component's can be interacted with
}));

我该怎么做?

0 个答案:

没有答案