fix(ivy): attach host element for views created via TestBed.createComponent (#31318)
Prior to this commit, host element of a view created via TestBed.createComponent was not attached to the component's host, making it problematic to use TestBed.createComponent API in component factories, which might be used for testing purposes only. This behavior is observed in google3 app tests and was supported by VE, so this commit aligns Ivy and VE. PR Close #31318
This commit is contained in:

committed by
Alex Rickabaugh

parent
a29dc961a2
commit
c12b6fa028
@ -1086,6 +1086,38 @@ describe('ViewContainerRef', () => {
|
||||
expect((element.namespaceURI || '').toLowerCase()).not.toContain('svg');
|
||||
});
|
||||
|
||||
it('should be compatible with componentRef generated via TestBed.createComponent in component factory',
|
||||
() => {
|
||||
@Component({
|
||||
selector: 'child',
|
||||
template: `Child Component`,
|
||||
})
|
||||
class Child {
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'comp',
|
||||
template: '<ng-template #ref></ng-template>',
|
||||
})
|
||||
class Comp {
|
||||
@ViewChild('ref', {read: ViewContainerRef, static: true})
|
||||
viewContainerRef?: ViewContainerRef;
|
||||
|
||||
ngOnInit() {
|
||||
const makeComponentFactory = (componentType: any) => ({
|
||||
create: () => TestBed.createComponent(componentType).componentRef,
|
||||
});
|
||||
this.viewContainerRef !.createComponent(makeComponentFactory(Child) as any);
|
||||
}
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({declarations: [Comp, Child]});
|
||||
|
||||
const fixture = TestBed.createComponent(Comp);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.debugElement.nativeElement.innerHTML).toContain('Child Component');
|
||||
});
|
||||
});
|
||||
|
||||
describe('insertion points and declaration points', () => {
|
||||
|
Reference in New Issue
Block a user