@@ -104,42 +104,58 @@ describe('ngRepeat', function() {
104
104
} ) ) ;
105
105
106
106
107
- it ( 'should expose iterator position as $position when iterating over arrays' ,
107
+ it ( 'should expose iterator position as $first, $middle and $last when iterating over arrays' ,
108
108
inject ( function ( $rootScope , $compile ) {
109
109
element = $compile (
110
110
'<ul>' +
111
- '<li ng-repeat="item in items" ng-bind=" item + \':\' + $position + \'|\'"> </li>' +
111
+ '<li ng-repeat="item in items">{{ item}}:{{$first}}-{{$middle}}-{{$last}}| </li>' +
112
112
'</ul>' ) ( $rootScope ) ;
113
113
$rootScope . items = [ 'misko' , 'shyam' , 'doug' ] ;
114
114
$rootScope . $digest ( ) ;
115
- expect ( element . text ( ) ) . toEqual ( 'misko:first|shyam:middle|doug:last|' ) ;
115
+ expect ( element . text ( ) ) .
116
+ toEqual ( 'misko:true-false-false|shyam:false-true-false|doug:false-false-true|' ) ;
116
117
117
118
$rootScope . items . push ( 'frodo' ) ;
118
119
$rootScope . $digest ( ) ;
119
- expect ( element . text ( ) ) . toEqual ( 'misko:first|shyam:middle|doug:middle|frodo:last|' ) ;
120
+ expect ( element . text ( ) ) .
121
+ toEqual ( 'misko:true-false-false|' +
122
+ 'shyam:false-true-false|' +
123
+ 'doug:false-true-false|' +
124
+ 'frodo:false-false-true|' ) ;
120
125
121
126
$rootScope . items . pop ( ) ;
122
127
$rootScope . items . pop ( ) ;
123
128
$rootScope . $digest ( ) ;
124
- expect ( element . text ( ) ) . toEqual ( 'misko:first|shyam:last|' ) ;
129
+ expect ( element . text ( ) ) . toEqual ( 'misko:true-false-false|shyam:false-false-true|' ) ;
130
+
131
+ $rootScope . items . pop ( ) ;
132
+ $rootScope . $digest ( ) ;
133
+ expect ( element . text ( ) ) . toEqual ( 'misko:true-false-true|' ) ;
125
134
} ) ) ;
126
135
127
136
128
- it ( 'should expose iterator position as $position when iterating over objects' ,
137
+ it ( 'should expose iterator position as $first, $middle and $last when iterating over objects' ,
129
138
inject ( function ( $rootScope , $compile ) {
130
139
element = $compile (
131
140
'<ul>' +
132
- '<li ng-repeat="(key, val) in items" ng-bind="key + \':\' + val + \':\' + $position + \'|\'">' +
133
- '</li>' +
141
+ '<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$first}}-{{$middle}}-{{$last}}|</li>' +
134
142
'</ul>' ) ( $rootScope ) ;
135
143
$rootScope . items = { 'misko' :'m' , 'shyam' :'s' , 'doug' :'d' , 'frodo' :'f' } ;
136
144
$rootScope . $digest ( ) ;
137
- expect ( element . text ( ) ) . toEqual ( 'doug:d:first|frodo:f:middle|misko:m:middle|shyam:s:last|' ) ;
145
+ expect ( element . text ( ) ) .
146
+ toEqual ( 'doug:d:true-false-false|' +
147
+ 'frodo:f:false-true-false|' +
148
+ 'misko:m:false-true-false|' +
149
+ 'shyam:s:false-false-true|' ) ;
138
150
139
151
delete $rootScope . items . doug ;
140
152
delete $rootScope . items . frodo ;
141
153
$rootScope . $digest ( ) ;
142
- expect ( element . text ( ) ) . toEqual ( 'misko:m:first|shyam:s:last|' ) ;
154
+ expect ( element . text ( ) ) . toEqual ( 'misko:m:true-false-false|shyam:s:false-false-true|' ) ;
155
+
156
+ delete $rootScope . items . shyam ;
157
+ $rootScope . $digest ( ) ;
158
+ expect ( element . text ( ) ) . toEqual ( 'misko:m:true-false-true|' ) ;
143
159
} ) ) ;
144
160
145
161
@@ -207,7 +223,7 @@ describe('ngRepeat', function() {
207
223
beforeEach ( inject ( function ( $rootScope , $compile ) {
208
224
element = $compile (
209
225
'<ul>' +
210
- '<li ng-repeat="item in items" ng-bind=" key + \':\' + val + \':\' + $position + \'|\'" ></li>' +
226
+ '<li ng-repeat="item in items">{{ key}}:{{ val}}| ></li>' +
211
227
'</ul>' ) ( $rootScope ) ;
212
228
a = { } ;
213
229
b = { } ;
0 commit comments