fix(ngRepeat): prevent initial duplicates

This commit is contained in:
Misko Hevery
2013-04-11 16:28:42 -07:00
parent a491ea3791
commit a0bc71e271
3 changed files with 33 additions and 10 deletions

View File

@@ -391,7 +391,7 @@ describe('ngRepeat', function() {
it('should iterate over non-existent elements of a sparse array', function() {
element = $compile('<ul><li ng-repeat="item in array">{{item}}|</li></ul>')(scope);
element = $compile('<ul><li ng-repeat="item in array track by $index">{{item}}|</li></ul>')(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];