@@ -353,7 +353,6 @@ describe('ngRepeat', function() {
353
353
expect ( element . text ( ) ) . toEqual ( 'misko:0|shyam:1|frodo:2|' ) ;
354
354
} ) ;
355
355
356
-
357
356
it ( 'should expose iterator offset as $index when iterating over objects' , function ( ) {
358
357
element = $compile (
359
358
'<ul>' +
@@ -395,6 +394,32 @@ describe('ngRepeat', function() {
395
394
} ) ;
396
395
397
396
397
+ it ( 'should expose iterator position as $even and $odd when iterating over arrays' ,
398
+ function ( ) {
399
+ element = $compile (
400
+ '<ul>' +
401
+ '<li ng-repeat="item in items">{{item}}:{{$even}}-{{$odd}}|</li>' +
402
+ '</ul>' ) ( scope ) ;
403
+ scope . items = [ 'misko' , 'shyam' , 'doug' ] ;
404
+ scope . $digest ( ) ;
405
+ expect ( element . text ( ) ) .
406
+ toEqual ( 'misko:true-false|shyam:false-true|doug:true-false|' ) ;
407
+
408
+ scope . items . push ( 'frodo' ) ;
409
+ scope . $digest ( ) ;
410
+ expect ( element . text ( ) ) .
411
+ toBe ( 'misko:true-false|' +
412
+ 'shyam:false-true|' +
413
+ 'doug:true-false|' +
414
+ 'frodo:false-true|' ) ;
415
+
416
+ scope . items . shift ( ) ;
417
+ scope . items . pop ( ) ;
418
+ scope . $digest ( ) ;
419
+ expect ( element . text ( ) ) . toBe ( 'shyam:true-false|doug:false-true|' ) ;
420
+ } ) ;
421
+
422
+
398
423
it ( 'should expose iterator position as $first, $middle and $last when iterating over objects' ,
399
424
function ( ) {
400
425
element = $compile (
@@ -420,6 +445,27 @@ describe('ngRepeat', function() {
420
445
} ) ;
421
446
422
447
448
+ it ( 'should expose iterator position as $even and $odd when iterating over objects' ,
449
+ function ( ) {
450
+ element = $compile (
451
+ '<ul>' +
452
+ '<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$even}}-{{$odd}}|</li>' +
453
+ '</ul>' ) ( scope ) ;
454
+ scope . items = { 'misko' :'m' , 'shyam' :'s' , 'doug' :'d' , 'frodo' :'f' } ;
455
+ scope . $digest ( ) ;
456
+ expect ( element . text ( ) ) .
457
+ toBe ( 'doug:d:true-false|' +
458
+ 'frodo:f:false-true|' +
459
+ 'misko:m:true-false|' +
460
+ 'shyam:s:false-true|' ) ;
461
+
462
+ delete scope . items . frodo ;
463
+ delete scope . items . shyam ;
464
+ scope . $digest ( ) ;
465
+ expect ( element . text ( ) ) . toBe ( 'doug:d:true-false|misko:m:false-true|' ) ;
466
+ } ) ;
467
+
468
+
423
469
it ( 'should calculate $first, $middle and $last when we filter out properties from an obj' , function ( ) {
424
470
element = $compile (
425
471
'<ul>' +
@@ -435,6 +481,21 @@ describe('ngRepeat', function() {
435
481
} ) ;
436
482
437
483
484
+ it ( 'should calculate $even and $odd when we filter out properties from an obj' , function ( ) {
485
+ element = $compile (
486
+ '<ul>' +
487
+ '<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$even}}-{{$odd}}|</li>' +
488
+ '</ul>' ) ( scope ) ;
489
+ scope . items = { 'misko' :'m' , 'shyam' :'s' , 'doug' :'d' , 'frodo' :'f' , '$toBeFilteredOut' : 'xxxx' } ;
490
+ scope . $digest ( ) ;
491
+ expect ( element . text ( ) ) .
492
+ toEqual ( 'doug:d:true-false|' +
493
+ 'frodo:f:false-true|' +
494
+ 'misko:m:true-false|' +
495
+ 'shyam:s:false-true|' ) ;
496
+ } ) ;
497
+
498
+
438
499
it ( 'should ignore $ and $$ properties' , function ( ) {
439
500
element = $compile ( '<ul><li ng-repeat="i in items">{{i}}|</li></ul>' ) ( scope ) ;
440
501
scope . items = [ 'a' , 'b' , 'c' ] ;
0 commit comments