@@ -649,6 +649,34 @@ describe("ngRepeat", () => {
649649 expect ( lis [ 1 ] . getAttribute ( "mark" ) ) . toEqual ( "a" ) ;
650650 } ) ;
651651
652+ it ( "should preserve repeated row DOM when the collection is shallow-cloned with the same items" , async ( ) => {
653+ element = $compile (
654+ '<ul><li ng-repeat="item in items">{{item.name}}|</li></ul>' ,
655+ ) ( scope ) ;
656+ const first = { name : "a" } ;
657+ const second = { name : "b" } ;
658+
659+ scope . items = [ first , second ] ;
660+ await wait ( ) ;
661+
662+ let lis = element . querySelectorAll ( "li" ) ;
663+ const firstRow = lis [ 0 ] ;
664+ const secondRow = lis [ 1 ] ;
665+
666+ firstRow . setAttribute ( "mark" , "first" ) ;
667+ secondRow . setAttribute ( "mark" , "second" ) ;
668+
669+ scope . items = [ ...scope . items ] ;
670+ await wait ( ) ;
671+
672+ lis = element . querySelectorAll ( "li" ) ;
673+ expect ( lis [ 0 ] ) . toBe ( firstRow ) ;
674+ expect ( lis [ 1 ] ) . toBe ( secondRow ) ;
675+ expect ( lis [ 0 ] . getAttribute ( "mark" ) ) . toBe ( "first" ) ;
676+ expect ( lis [ 1 ] . getAttribute ( "mark" ) ) . toBe ( "second" ) ;
677+ expect ( element . textContent ) . toBe ( "a|b|" ) ;
678+ } ) ;
679+
652680 it ( "keeps grouped interpolation bindings when archived items are removed" , async ( ) => {
653681 element = $compile (
654682 '<ul><li ng-repeat="todo in tasks">{{todo.task}} {{todo.done}}|</li></ul>' ,
@@ -667,6 +695,24 @@ describe("ngRepeat", () => {
667695 await wait ( ) ;
668696 expect ( element . textContent ) . toBe ( "Build an AngularTS app false|" ) ;
669697 } ) ;
698+
699+ it ( "updates repeated rows when an array item object is replaced by index" , async ( ) => {
700+ element = $compile (
701+ '<ul><li ng-repeat="todo in tasks">{{todo.task}} {{todo.done}}|</li></ul>' ,
702+ ) ( scope ) ;
703+ scope . tasks = [
704+ { task : "First Task" , done : false } ,
705+ { task : "Second Task" , done : true } ,
706+ ] ;
707+
708+ await wait ( ) ;
709+ expect ( element . textContent ) . toBe ( "First Task false|Second Task true|" ) ;
710+
711+ scope . tasks [ 0 ] = { task : "New Task" , done : false } ;
712+ await wait ( ) ;
713+
714+ expect ( element . textContent ) . toBe ( "New Task false|Second Task true|" ) ;
715+ } ) ;
670716 } ) ;
671717
672718 describe ( "nesting in replaced directive templates" , ( ) => {
0 commit comments