fix(ivy): descend into view containers on ng-container when collecting rootNodes (#33493)

PR Close #33493
This commit is contained in:
Pawel Kozlowski
2019-10-30 13:39:55 +01:00
committed by Andrew Kushnir
parent 87743f1aa1
commit a5167bd53c
2 changed files with 53 additions and 19 deletions

View File

@ -171,6 +171,38 @@ describe('TemplateRef', () => {
expect(embeddedView.rootNodes[2].nodeType).toBe(Node.TEXT_NODE);
});
it('should descend into view containers on ng-container', () => {
/**
* NOTE: In VE, if `SUFFIX` text node below is _not_ present, VE will add an
* additional `<!---->` comment, thus being slightly different than Ivy.
* (resulting in 1 root node in Ivy and 2 in VE).
*/
@Component({
template: `
<ng-template #dynamicTpl>text</ng-template>
<ng-template #templateRef><ng-container [ngTemplateOutlet]="dynamicTpl"></ng-container>SUFFIX</ng-template>
`
})
class App {
@ViewChild('templateRef', {static: true})
templateRef !: TemplateRef<any>;
}
TestBed.configureTestingModule({
declarations: [App],
});
const fixture = TestBed.createComponent(App);
fixture.detectChanges();
const embeddedView = fixture.componentInstance.templateRef.createEmbeddedView({});
embeddedView.detectChanges();
expect(embeddedView.rootNodes.length).toBe(3);
expect(embeddedView.rootNodes[0].nodeType).toBe(Node.COMMENT_NODE);
expect(embeddedView.rootNodes[1].nodeType).toBe(Node.TEXT_NODE);
expect(embeddedView.rootNodes[2].nodeType).toBe(Node.TEXT_NODE);
});
it('should descend into element containers when retrieving root nodes', () => {
@Component({
template: `