@@ -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,54 @@ 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 item is being watched and it is removed' , () {
405
+ element = compile (
406
+ '<ul>'
407
+ ' <li ng-repeat="i in items">'
408
+ ' <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 item is being watched and it is removed' , () {
420
+ element = compile (
421
+ '<ul>'
422
+ ' <li ng-repeat="i in items">'
423
+ ' <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 an items are being watched and multiple items are removed '
435
+ 'at the same time' , () {
436
+ element = compile (
437
+ '<ul>'
438
+ ' <li ng-repeat="i in items">'
439
+ ' <input ng-model="items[\$ index]">'
440
+ ' </li>'
441
+ '</ul>' );
442
+ scope.context['items' ] = ['misko' , 'shyam' , 'frodo' , 'igor' ];
443
+ scope.apply ();
444
+ expect (element.children.length).toEqual (4 );
445
+ scope.context['items' ].remove ('shyam' );
446
+ scope.context['items' ].remove ('frodo' );
447
+ scope.apply ();
448
+ expect (element.children.length).toEqual (2 );
449
+ });
450
+ });
404
451
405
452
describe ('stability' , () {
406
453
var a, b, c, d, lis;
@@ -420,7 +467,6 @@ main() {
420
467
lis = element.querySelectorAll ('li' );
421
468
});
422
469
423
-
424
470
it (r'should preserve the order of elements' , () {
425
471
scope.context['items' ] = [a, c, d];
426
472
scope.apply ();
0 commit comments