I have a class that uses the Injector as below
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.
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/angular/bbea31a4-1768-48a9-a8e4-f693f16c97bd%40googlegroups.com.