@@ -135,39 +135,76 @@ describe("directives", function(){
135
135
expect ( element . text ( ) ) . toEqual ( '' ) ;
136
136
} ) ;
137
137
138
- it ( 'should ng:repeat over array' , function ( ) {
139
- var scope = compile ( '<ul><li ng:repeat="item in items" ng:init="suffix = \';\'" ng:bind="item + suffix"></li></ul>' ) ;
140
138
141
- Array . prototype . extraProperty = "should be ignored" ;
142
- scope . items = [ 'misko' , 'shyam' ] ;
143
- scope . $eval ( ) ;
144
- expect ( element . text ( ) ) . toEqual ( 'misko;shyam;' ) ;
145
- delete Array . prototype . extraProperty ;
139
+ describe ( 'ng:repeat' , function ( ) {
146
140
147
- scope . items = [ 'adam' , 'kai' , 'brad' ] ;
148
- scope . $eval ( ) ;
149
- expect ( element . text ( ) ) . toEqual ( 'adam;kai;brad;' ) ;
141
+ it ( 'should ng:repeat over array' , function ( ) {
142
+ var scope = compile ( '<ul><li ng:repeat="item in items" ng:init="suffix = \';\'" ng:bind="item + suffix"></li></ul>' ) ;
150
143
151
- scope . items = [ 'brad' ] ;
152
- scope . $eval ( ) ;
153
- expect ( element . text ( ) ) . toEqual ( 'brad;' ) ;
154
- } ) ;
144
+ Array . prototype . extraProperty = "should be ignored" ;
145
+ scope . items = [ 'misko' , 'shyam' ] ;
146
+ scope . $eval ( ) ;
147
+ expect ( element . text ( ) ) . toEqual ( 'misko;shyam;' ) ;
148
+ delete Array . prototype . extraProperty ;
155
149
156
- it ( 'should ng:repeat over object' , function ( ) {
157
- var scope = compile ( '<ul><li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li></ul>' ) ;
158
- scope . $set ( 'items' , { misko :'swe' , shyam :'set' } ) ;
159
- scope . $eval ( ) ;
160
- expect ( element . text ( ) ) . toEqual ( 'misko:swe;shyam:set;' ) ;
161
- } ) ;
150
+ scope . items = [ 'adam' , 'kai' , 'brad' ] ;
151
+ scope . $eval ( ) ;
152
+ expect ( element . text ( ) ) . toEqual ( 'adam;kai;brad;' ) ;
153
+
154
+ scope . items = [ 'brad' ] ;
155
+ scope . $eval ( ) ;
156
+ expect ( element . text ( ) ) . toEqual ( 'brad;' ) ;
157
+ } ) ;
158
+
159
+ it ( 'should ng:repeat over object' , function ( ) {
160
+ var scope = compile ( '<ul><li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li></ul>' ) ;
161
+ scope . $set ( 'items' , { misko :'swe' , shyam :'set' } ) ;
162
+ scope . $eval ( ) ;
163
+ expect ( element . text ( ) ) . toEqual ( 'misko:swe;shyam:set;' ) ;
164
+ } ) ;
162
165
163
- it ( 'should error on wrong parsing of ng:repeat' , function ( ) {
164
- var scope = compile ( '<ul><li ng:repeat="i dont parse"></li></ul>' ) ;
165
- var log = "" ;
166
- log += element . attr ( 'ng-exception' ) + ';' ;
167
- log += element . hasClass ( 'ng-exception' ) + ';' ;
168
- expect ( log ) . toEqual ( "\"Expected ng:repeat in form of 'item in collection' but got 'i dont parse'.\";true;" ) ;
166
+ it ( 'should error on wrong parsing of ng:repeat' , function ( ) {
167
+ var scope = compile ( '<ul><li ng:repeat="i dont parse"></li></ul>' ) ;
168
+ var log = "" ;
169
+ log += element . attr ( 'ng-exception' ) + ';' ;
170
+ log += element . hasClass ( 'ng-exception' ) + ';' ;
171
+ expect ( log ) . toEqual ( "\"Expected ng:repeat in form of 'item in collection' but got 'i dont parse'.\";true;" ) ;
172
+ } ) ;
173
+
174
+ it ( 'should expose iterator offset as $index when iterating over arrays' , function ( ) {
175
+ var scope = compile ( '<ul><li ng:repeat="item in items" ' +
176
+ 'ng:bind="item + $index + \'|\'"></li></ul>' ) ;
177
+ scope . items = [ 'misko' , 'shyam' , 'frodo' ] ;
178
+ scope . $eval ( ) ;
179
+ expect ( element . text ( ) ) . toEqual ( 'misko0|shyam1|frodo2|' ) ;
180
+ } ) ;
181
+
182
+ it ( 'should expose iterator offset as $index when iterating over objects' , function ( ) {
183
+ var scope = compile ( '<ul><li ng:repeat="(key, val) in items" ' +
184
+ 'ng:bind="key + \':\' + val + $index + \'|\'"></li></ul>' ) ;
185
+ scope . items = { 'misko' :'m' , 'shyam' :'s' , 'frodo' :'f' } ;
186
+ scope . $eval ( ) ;
187
+ expect ( element . text ( ) ) . toEqual ( 'misko:m0|shyam:s1|frodo:f2|' ) ;
188
+ } ) ;
189
+
190
+ it ( 'should expose iterator position as $position when iterating over arrays' , function ( ) {
191
+ var scope = compile ( '<ul><li ng:repeat="item in items" ' +
192
+ 'ng:bind="item + \':\' + $position + \'|\'"></li></ul>' ) ;
193
+ scope . items = [ 'misko' , 'shyam' , 'doug' , 'frodo' ] ;
194
+ scope . $eval ( ) ;
195
+ expect ( element . text ( ) ) . toEqual ( 'misko:first|shyam:middle|doug:middle|frodo:last|' ) ;
196
+ } ) ;
197
+
198
+ it ( 'should expose iterator position as $position when iterating over objects' , function ( ) {
199
+ var scope = compile ( '<ul><li ng:repeat="(key, val) in items" ' +
200
+ 'ng:bind="key + \':\' + val + \':\' + $position + \'|\'"></li></ul>' ) ;
201
+ scope . items = { 'misko' :'m' , 'shyam' :'s' , 'doug' :'d' , 'frodo' :'f' } ;
202
+ scope . $eval ( ) ;
203
+ expect ( element . text ( ) ) . toEqual ( 'misko:m:first|shyam:s:middle|doug:d:middle|frodo:f:last|' ) ;
204
+ } ) ;
169
205
} ) ;
170
206
207
+
171
208
it ( 'should ng:watch' , function ( ) {
172
209
var scope = compile ( '<div ng:watch="i: count = count + 1" ng:init="count = 0">' ) ;
173
210
scope . $eval ( ) ;
0 commit comments