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

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'));

Leave a Comment

error code: 521