angular - Modificar un componente definido en TestBed.overrideComponent
typescript integration-testing (1)
Estamos usando
TestBed.overrideComponent(CoolComponent, {
set: {
template: ''<div id="fake-component">i am the fake component</div>'',
selector: ''our-cool-component'',
inputs: [ ''model'' ]
}
})
para anular un componente.
El componente tiene un ViewChild que configuramos en nuestro método ngOnInit
@Component({
selector: ''our-cool-component'',
templateUrl: ''cool.component.html''
})
export class CoolComponent implements OnInit, OnDestroy {
@Input() model: SomeModel
@ViewChild(CoolChildComponent) coolChildComponent;
ngOnInit() {
this.coolChildComponent.doStuff();
}
}
El CoolComponent a su vez, vive en un componente Wrapper .
Cuando llamamos a fixture.detectChanges() en el dispositivo Wrapper , esto intenta construir el CoolComponent, pero muere inmediatamente cuando llama a doStuff () porque CoolChildComponent no está definido.
¿Hay alguna manera de llegar al CoolComponent para CoolChildComponent su CoolChildComponent ? No parece que podamos sacarlo del Wrapper porque solo se hace referencia a través de la plantilla, no como una propiedad del componente.
ngOnInit() {
this.coolChildComponent.doStuff();
}
debiera ser
ngAfterViewInit() {
this.coolChildComponent.doStuff();
}
La vista secundaria se establece antes de llamar a la devolución de llamada ngAfterViewInit.