fix(ivy): descend into view containers on elements when collecting rootNodes (#33493)

PR Close #33493
This commit is contained in:
Pawel Kozlowski
2019-10-30 12:07:27 +01:00
committed by Andrew Kushnir
parent 502fb7e307
commit 87743f1aa1
2 changed files with 50 additions and 13 deletions

View File

@ -139,6 +139,38 @@ describe('TemplateRef', () => {
expect(embeddedView.rootNodes[2].nodeType).toBe(Node.TEXT_NODE);
});
it('should descend into view containers on an element', () => {
/**
* 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><div [ngTemplateOutlet]="dynamicTpl"></div>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.ELEMENT_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: `