diff options
| author | Igor Minar | 2011-10-24 09:18:44 -0700 |
|---|---|---|
| committer | Igor Minar | 2011-10-26 12:54:00 -0700 |
| commit | 3945f884c5777e629b57c9ab0e93b9d02b9840d0 (patch) | |
| tree | ba4928d4b51e1b19a12f8da2473307aa8b505d47 /test | |
| parent | d5ccabce600efb10092fdf0ae033c009026bf4cb (diff) | |
| download | angular.js-3945f884c5777e629b57c9ab0e93b9d02b9840d0.tar.bz2 | |
fix(ng:repeat) with array ignore properties not representing array elements
Along the way I also changed the repeater impl to use for loop instead
of for in loop.
Iteration over objects is handled by creating an array of keys, which is
sorted and this array then determines the order of iteration over an
element. This makes repeating over objects deterministic and
cross-browser compatible.
Diffstat (limited to 'test')
| -rw-r--r-- | test/widgetsSpec.js | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 4aa36428..b93d698d 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -254,7 +254,7 @@ describe("widget", function() { 'ng:bind="key + \':\' + val + $index + \'|\'"></li></ul>'); scope.items = {'misko':'m', 'shyam':'s', 'frodo':'f'}; scope.$digest(); - expect(element.text()).toEqual('misko:m0|shyam:s1|frodo:f2|'); + expect(element.text()).toEqual('frodo:f0|misko:m1|shyam:s2|'); }); it('should expose iterator position as $position when iterating over arrays', function() { @@ -282,7 +282,7 @@ describe("widget", function() { '</ul>'); scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f'}; scope.$digest(); - expect(element.text()).toEqual('misko:m:first|shyam:s:middle|doug:d:middle|frodo:f:last|'); + expect(element.text()).toEqual('doug:d:first|frodo:f:middle|misko:m:middle|shyam:s:last|'); delete scope.items.doug; delete scope.items.frodo; @@ -312,6 +312,26 @@ describe("widget", function() { expect(element.text()).toEqual('a|b|Xc|d|X'); }); + it('should ignore non-array element properties when iterating over an array', function() { + var scope = compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>'); + scope.array = ['a', 'b', 'c']; + scope.array.foo = '23'; + scope.array.bar = function() {}; + scope.$digest(); + + expect(element.text()).toBe('a|b|c|'); + }); + + it('should iterate over non-existent elements of a sparse array', function() { + var scope = compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>'); + scope.array = ['a', 'b']; + scope.array[4] = 'c'; + scope.array[6] = 'd'; + scope.$digest(); + + expect(element.text()).toBe('a|b|||c||d|'); + }); + describe('stability', function() { var a, b, c, d, scope, lis; |
