export class DetailsComponent implements OnInit, IContainer {
views: ViewDetails[];
// static true run before change detection
@ViewChild('detailsRegion', { read: ViewContainerRef, static: true })
detailsRegion: ViewContainerRef;
constructor(private injector: Injector) {}
private insertView(
viewContainer: ViewContainerRef,
componentFactory: ComponentFactory<any>
) {
const compRef = componentFactory.create(this.injector);
viewContainer.clear();
viewContainer.insert(compRef.hostView);
}
ngOnInit() {}
public insertsView(views: ViewDetails[]): void {
this.views = views;
views.forEach(v => {
switch (v.region) {
case ContainerView.Details:
this.insertView(this.detailsRegion, v.componentFactory);
break;
case ContainerView.Master:
case ContainerView.Map:
throw new Error('Out of Range');
}
});
}
}
When writing the unit test how do I capture the Injector so I can set up the component factory spy object to ensure that create is correctly called with it. I have tried setting up a provider in TestBed.configureTestingModule with no success.