@@ -327,7 +327,6 @@ main() {
327
327
expect (element.text).toEqual ('misko:0|shyam:1|frodo:2|' );
328
328
});
329
329
330
-
331
330
it (r'should expose iterator position as $first, $middle and $last when iterating over arrays' ,
332
331
() {
333
332
element = compile (
@@ -401,6 +400,53 @@ main() {
401
400
expect (element.text).toEqual ('a|b|Xc|d|X' );
402
401
});
403
402
403
+ describe ('nested watching' , () {
404
+ it ('should not error when the first watched item is removed' , () {
405
+ element = compile (
406
+ '<ul>'
407
+ ' <li ng-repeat="i in items">'
408
+ r' <input ng-model="items[$index]">'
409
+ ' </li>'
410
+ '</ul>' );
411
+ scope.context['items' ] = ['misko' , 'shyam' , 'frodo' ];
412
+ scope.apply ();
413
+ expect (element.children.length).toEqual (3 );
414
+ scope.context['items' ].remove ('misko' );
415
+ scope.apply ();
416
+ expect (element.children.length).toEqual (2 );
417
+ });
418
+
419
+ it ('should not error when the last watched item is removed' , () {
420
+ element = compile (
421
+ '<ul>'
422
+ ' <li ng-repeat="i in items">'
423
+ r' <input ng-model="items[$index]">'
424
+ ' </li>'
425
+ '</ul>' );
426
+ scope.context['items' ] = ['misko' , 'shyam' , 'frodo' ];
427
+ scope.apply ();
428
+ expect (element.children.length).toEqual (3 );
429
+ scope.context['items' ].remove ('frodo' );
430
+ scope.apply ();
431
+ expect (element.children.length).toEqual (2 );
432
+ });
433
+
434
+ it ('should not error when multiple watched items are removed at the same time' , () {
435
+ element = compile (
436
+ '<ul>'
437
+ ' <li ng-repeat="i in items">'
438
+ r' <input ng-model="items[$index]">'
439
+ ' </li>'
440
+ '</ul>' );
441
+ scope.context['items' ] = ['misko' , 'shyam' , 'frodo' , 'igor' ];
442
+ scope.apply ();
443
+ expect (element.children.length).toEqual (4 );
444
+ scope.context['items' ].remove ('shyam' );
445
+ scope.context['items' ].remove ('frodo' );
446
+ scope.apply ();
447
+ expect (element.children.length).toEqual (2 );
448
+ });
449
+ });
404
450
405
451
describe ('stability' , () {
406
452
var a, b, c, d, lis;
@@ -420,7 +466,6 @@ main() {
420
466
lis = element.querySelectorAll ('li' );
421
467
});
422
468
423
-
424
469
it (r'should preserve the order of elements' , () {
425
470
scope.context['items' ] = [a, c, d];
426
471
scope.apply ();
0 commit comments