Skip to content
Permalink
Browse files

fix(ivy): consistenly return -1 from ViewContainerRef.indexOf for non…

…-inserted view (#34156)

PR Close #34156
  • Loading branch information
pkozlowski-opensource authored and mhevery committed Nov 29, 2019
1 parent 91f4b81 commit 0044c6621ea2eef76162463b4b5f9b49a7188385
@@ -281,9 +281,8 @@ export function createContainerRef(
}

indexOf(viewRef: viewEngine_ViewRef): number {
return this._lContainer[VIEW_REFS] !== null ?
this._lContainer[VIEW_REFS] !.indexOf(viewRef) :
0;
const viewRefsArr = this._lContainer[VIEW_REFS];
return viewRefsArr !== null ? viewRefsArr.indexOf(viewRef) : -1;
}

remove(index?: number): void {
@@ -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', () => {

0 comments on commit 0044c66

Please sign in to comment.
You can’t perform that action at this time.