fix(ivy): consistenly return -1 from ViewContainerRef.indexOf for non-inserted view (#34156)

PR Close #34156
This commit is contained in:
Pawel Kozlowski
2019-11-29 22:29:00 +01:00
committed by Miško Hevery
parent 91f4b81f79
commit 0044c6621e
2 changed files with 20 additions and 3 deletions

View File

@ -478,6 +478,24 @@ describe('ViewContainerRef', () => {
vcRefDir.vcref.remove(0);
expect(vcRefDir.vcref.indexOf(viewRef !)).toEqual(-1);
});
it('should return -1 as indexOf when no views were inserted', () => {
const fixture = TestBed.createComponent(ViewContainerRefComp);
fixture.detectChanges();
const cmpt = fixture.componentInstance;
const viewRef = cmpt.templates.first.createEmbeddedView({});
// ViewContainerRef is empty and we've got a reference to a view that was not attached
// anywhere
expect(cmpt.vcr.indexOf(viewRef)).toBe(-1);
cmpt.vcr.insert(viewRef);
expect(cmpt.vcr.indexOf(viewRef)).toBe(0);
cmpt.vcr.remove(0);
expect(cmpt.vcr.indexOf(viewRef)).toBe(-1);
});
});
describe('move', () => {