I am testing the component as shown below.
@Component({
selector: 'my-component',
template: `
<my-nested-component [state]="state"></my-nested-component>
`,
encapsulation: ViewEncapsulation.Native
})
export class MyComponent {}
When a module tests my component, I want to get a link to a nested component MyOtherComponent. If you my-componentdid not use encapsulation or used emulated encapsulation, I could use:
let fixture = TestBed.createComponent(MyComponent);
let nestedComponent = fixture.debugElement.query(By.directive(MyNestedComponent))
to get a link to the component.
But in this case, it querysimply requests light child elements of the DOM component (simulates the behavior querySelector), therefore, nestedComponent nullwhen using the built-in encapsulation of the view.
How should you get a reference to DebugElement(and therefore to a component instance) a nested component?