diff options
| author | Misko Hevery | 2013-04-11 16:28:42 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2013-04-11 23:06:07 -0700 | 
| commit | a0bc71e27107c58282e71415c4e8d89e916ae99c (patch) | |
| tree | 774f767d2a780c32bed407e00637a97f1b9ac023 /test/ng/directive | |
| parent | a491ea3791eb56e9932e12ded1395e0e5e99355a (diff) | |
| download | angular.js-a0bc71e27107c58282e71415c4e8d89e916ae99c.tar.bz2 | |
fix(ngRepeat): prevent initial duplicates
Diffstat (limited to 'test/ng/directive')
| -rw-r--r-- | test/ng/directive/ngRepeatSpec.js | 26 | 
1 files changed, 23 insertions, 3 deletions
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('<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];  | 
