test(ng-container): test nesting ng-containers
This commit is contained in:
parent
8e6e90e703
commit
9cbd8f7afc
|
@ -78,7 +78,7 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
|
|||
}
|
||||
|
||||
private _getParentRenderNode(parent: CompileElement): o.Expression {
|
||||
parent = <CompileElement>_getOuterContainerParentOrSelf(parent);
|
||||
parent = _getOuterContainerParentOrSelf(parent);
|
||||
if (this._isRootNode(parent)) {
|
||||
if (this.view.viewType === ViewType.COMPONENT) {
|
||||
return parentRenderNodeVar;
|
||||
|
|
|
@ -33,7 +33,6 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
tcb.overrideTemplate(MyComp, '<ng-container><p></p></ng-container>')
|
||||
.createAsync(MyComp)
|
||||
.then((fixture) => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const el = fixture.debugElement.nativeElement;
|
||||
|
@ -46,6 +45,30 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
});
|
||||
}));
|
||||
|
||||
it('should support nesting',
|
||||
inject(
|
||||
[TestComponentBuilder, AsyncTestCompleter],
|
||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.overrideTemplate(
|
||||
MyComp,
|
||||
'<ng-container>1</ng-container><ng-container><ng-container>2</ng-container></ng-container>')
|
||||
.createAsync(MyComp)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
|
||||
const el = fixture.debugElement.nativeElement;
|
||||
const children = getDOM().childNodes(el);
|
||||
expect(children.length).toBe(5);
|
||||
expect(getDOM().isCommentNode(children[0])).toBe(true);
|
||||
expect(children[1]).toHaveText('1');
|
||||
expect(getDOM().isCommentNode(children[2])).toBe(true);
|
||||
expect(getDOM().isCommentNode(children[3])).toBe(true);
|
||||
expect(children[4]).toHaveText('2');
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should group inner nodes',
|
||||
inject(
|
||||
[TestComponentBuilder, AsyncTestCompleter],
|
||||
|
@ -87,8 +110,10 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
.createAsync(MyComp)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
|
||||
const el = fixture.debugElement.nativeElement;
|
||||
expect(el).toHaveText('SIMPLE(12)');
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
@ -102,9 +127,11 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
.createAsync(MyComp)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
|
||||
const dir = fixture.debugElement.children[0].injector.get(TextDirective);
|
||||
expect(dir).toBeAnInstanceOf(TextDirective);
|
||||
expect(dir.text).toEqual('container');
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
@ -118,9 +145,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
|
||||
tcb.overrideTemplate(MyComp, template).createAsync(MyComp).then((view) => {
|
||||
view.detectChanges();
|
||||
|
||||
var q = view.debugElement.children[0].references['q'];
|
||||
|
||||
view.detectChanges();
|
||||
|
||||
expect(q.textDirChildren.length).toEqual(1);
|
||||
|
@ -138,9 +163,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
|
||||
tcb.overrideTemplate(MyComp, template).createAsync(MyComp).then((view) => {
|
||||
view.detectChanges();
|
||||
|
||||
var q = view.debugElement.children[0].references['q'];
|
||||
|
||||
view.detectChanges();
|
||||
|
||||
expect(q.textDirChildren.length).toEqual(1);
|
||||
|
|
Loading…
Reference in New Issue