From a0bc71e27107c58282e71415c4e8d89e916ae99c Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 11 Apr 2013 16:28:42 -0700 Subject: fix(ngRepeat): prevent initial duplicates --- test/ng/directive/ngRepeatSpec.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 070e6e02..7376b670 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -391,7 +391,7 @@ describe('ngRepeat', function() { it('should iterate over non-existent elements of a sparse array', function() { - element = $compile('')(scope); + element = $compile('')(scope); scope.array = ['a', 'b']; scope.array[4] = 'c'; scope.array[6] = 'd'; @@ -457,11 +457,31 @@ describe('ngRepeat', function() { }); - it('should throw error on duplicates and recover', function() { + it('should throw error on adding existing duplicates and recover', function() { scope.items = [a, a, a]; scope.$digest(); expect($exceptionHandler.errors.shift().message). - toEqual('Duplicates in a repeater are not allowed. Repeater: item in items'); + toEqual('Duplicates in a repeater are not allowed. Repeater: item in items key: object:003'); + + // recover + scope.items = [a]; + scope.$digest(); + var newElements = element.find('li'); + expect(newElements.length).toEqual(1); + expect(newElements[0]).toEqual(lis[0]); + + scope.items = []; + scope.$digest(); + var newElements = element.find('li'); + expect(newElements.length).toEqual(0); + }); + + + it('should throw error on new duplicates and recover', function() { + scope.items = [d, d, d]; + scope.$digest(); + expect($exceptionHandler.errors.shift().message). + toEqual('Duplicates in a repeater are not allowed. Repeater: item in items key: object:009'); // recover scope.items = [a]; -- cgit v1.2.3