From cda35101df8dbd705e7fc1e4c69d0ae465367386 Mon Sep 17 00:00:00 2001 From: Tim Blasi Date: Wed, 27 May 2015 18:16:02 -0700 Subject: [PATCH] fix(facade): Fix bug in TS indexOf startIndex defaults to -1, which in Chrome results in returning -1 regardless of the other parameters. Added regression tests. --- modules/angular2/src/facade/collection.ts | 2 +- modules/angular2/test/facade/collection_spec.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/facade/collection.ts b/modules/angular2/src/facade/collection.ts index 2582210b7b..5c2ed52ee3 100644 --- a/modules/angular2/src/facade/collection.ts +++ b/modules/angular2/src/facade/collection.ts @@ -171,7 +171,7 @@ export class ListWrapper { } return null; } - static indexOf(array: List, value, startIndex = -1) { + static indexOf(array: List, value, startIndex = 0) { return array.indexOf(value, startIndex); } static reduce(list: List, diff --git a/modules/angular2/test/facade/collection_spec.ts b/modules/angular2/test/facade/collection_spec.ts index e9d121378f..832de208c5 100644 --- a/modules/angular2/test/facade/collection_spec.ts +++ b/modules/angular2/test/facade/collection_spec.ts @@ -58,6 +58,18 @@ export function main() { it('should support negative end', () => { expect(ListWrapper.slice(l, -3, -1)).toEqual([2, 3]); }); }); + + describe('indexOf', () => { + beforeEach(() => { l = [1, 2, 3, 4]; }); + + it('should find values that exist', () => { expect(ListWrapper.indexOf(l, 1)).toEqual(0); }); + + it('should not find values that do not exist', + () => { expect(ListWrapper.indexOf(l, 9)).toEqual(-1); }); + + it('should respect the startIndex parameter', + () => { expect(ListWrapper.indexOf(l, 1, 1)).toEqual(-1); }); + }); }); describe('StringMapWrapper', () => {