diff options
| author | P. Envall | 2013-07-19 17:02:17 +0200 |
|---|---|---|
| committer | Ken Sheedlo | 2013-07-24 15:37:10 -0700 |
| commit | 52b8211fd0154b9d6b771a83573a161f5580d92c (patch) | |
| tree | 426dfef5cffa01f320763a1bc5e92d165de0eb8e /test/ng/directive/ngRepeatSpec.js | |
| parent | 0fcd1e3b1fa6244d02f08631d9ef81bf79996fab (diff) | |
| download | angular.js-52b8211fd0154b9d6b771a83573a161f5580d92c.tar.bz2 | |
feat(ngRepeat): add $even and $odd props to iterator
Diffstat (limited to 'test/ng/directive/ngRepeatSpec.js')
| -rw-r--r-- | test/ng/directive/ngRepeatSpec.js | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 0d1833c8..26562f4e 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -353,7 +353,6 @@ describe('ngRepeat', function() { expect(element.text()).toEqual('misko:0|shyam:1|frodo:2|'); }); - it('should expose iterator offset as $index when iterating over objects', function() { element = $compile( '<ul>' + @@ -395,6 +394,32 @@ describe('ngRepeat', function() { }); + it('should expose iterator position as $even and $odd when iterating over arrays', + function() { + element = $compile( + '<ul>' + + '<li ng-repeat="item in items">{{item}}:{{$even}}-{{$odd}}|</li>' + + '</ul>')(scope); + scope.items = ['misko', 'shyam', 'doug']; + scope.$digest(); + expect(element.text()). + toEqual('misko:true-false|shyam:false-true|doug:true-false|'); + + scope.items.push('frodo'); + scope.$digest(); + expect(element.text()). + toBe('misko:true-false|' + + 'shyam:false-true|' + + 'doug:true-false|' + + 'frodo:false-true|'); + + scope.items.shift(); + scope.items.pop(); + scope.$digest(); + expect(element.text()).toBe('shyam:true-false|doug:false-true|'); + }); + + it('should expose iterator position as $first, $middle and $last when iterating over objects', function() { element = $compile( @@ -420,6 +445,27 @@ describe('ngRepeat', function() { }); + it('should expose iterator position as $even and $odd when iterating over objects', + function() { + element = $compile( + '<ul>' + + '<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$even}}-{{$odd}}|</li>' + + '</ul>')(scope); + scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f'}; + scope.$digest(); + expect(element.text()). + toBe('doug:d:true-false|' + + 'frodo:f:false-true|' + + 'misko:m:true-false|' + + 'shyam:s:false-true|'); + + delete scope.items.frodo; + delete scope.items.shyam; + scope.$digest(); + expect(element.text()).toBe('doug:d:true-false|misko:m:false-true|'); + }); + + it('should calculate $first, $middle and $last when we filter out properties from an obj', function() { element = $compile( '<ul>' + @@ -435,6 +481,21 @@ describe('ngRepeat', function() { }); + it('should calculate $even and $odd when we filter out properties from an obj', function() { + element = $compile( + '<ul>' + + '<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$even}}-{{$odd}}|</li>' + + '</ul>')(scope); + scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f', '$toBeFilteredOut': 'xxxx'}; + scope.$digest(); + expect(element.text()). + toEqual('doug:d:true-false|' + + 'frodo:f:false-true|' + + 'misko:m:true-false|' + + 'shyam:s:false-true|'); + }); + + it('should ignore $ and $$ properties', function() { element = $compile('<ul><li ng-repeat="i in items">{{i}}|</li></ul>')(scope); scope.items = ['a', 'b', 'c']; |
