Angular 5 testing: how to get a reference to the child component

前端 未结 3 1764
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 12:06

I\'m trying to test the interaction between a host component and a child component in an Angular application. I don\'t know how to get a reference to the child component c

3条回答
  •  无人及你
    2020-12-24 12:42

    As explained in the guide, host component instance is created with TestBed.createComponent, and child component instance can be selected from debugElement with By helper:

    childDebugElement = hostFixture.debugElement.query(By.directive(ChildComponent));
    

    Or:

    childDebugElement = hostFixture.debugElement.query(By.css('child'));
    

提交回复
热议问题