@@ -657,48 +657,61 @@ describe('ngOptions', function() {
657
657
} ) ;
658
658
659
659
660
- it ( 'should update the selected item when only the properties on the object change (single)' , function ( ) {
660
+ it ( 'should update the selected option even if only the tracked property on the selected object changes (single)' , function ( ) {
661
661
createSelect ( {
662
662
'ng-model' : 'selected' ,
663
663
'ng-options' : 'item.label for item in arr track by item.id'
664
664
} ) ;
665
665
666
666
scope . $apply ( function ( ) {
667
- scope . selected = { id : 10 , label : 'new ten' } ;
667
+ scope . selected = { id : 10 , label : 'ten' } ;
668
668
} ) ;
669
669
670
- expect ( element . val ( ) ) . toBe ( '10' ) ;
670
+ expect ( element . val ( ) ) . toEqual ( '10' ) ;
671
671
672
- // Update the properties on the
672
+ // Update the properties on the selected object, rather than replacing the whole object
673
673
scope . $apply ( function ( ) {
674
674
scope . selected . id = 20 ;
675
675
scope . selected . label = 'new twenty' ;
676
676
} ) ;
677
677
678
- expect ( element . val ( ) ) . toBe ( '20' ) ;
678
+ // The value of the select should change since the id property changed
679
+ expect ( element . val ( ) ) . toEqual ( '20' ) ;
680
+
681
+ // But the label of the selected option does not change
682
+ var option = element . find ( 'option' ) . eq ( 1 ) ;
683
+ expect ( option . prop ( 'selected' ) ) . toEqual ( true ) ;
684
+ expect ( option . text ( ) ) . toEqual ( 'twenty' ) ; // not 'new twenty'
679
685
} ) ;
680
686
681
687
682
- it ( 'should update the selected item when only the properties on the object change (multi)' , function ( ) {
688
+ it ( 'should update the selected options even if only the tracked properties on the objects in the ' +
689
+ 'selected collection change (multi)' , function ( ) {
683
690
createSelect ( {
684
691
'ng-model' : 'selected' ,
685
692
'multiple' : true ,
686
693
'ng-options' : 'item.label for item in arr track by item.id'
687
694
} ) ;
688
695
689
696
scope . $apply ( function ( ) {
690
- scope . selected = [ { id : 10 , label : 'new ten' } ] ;
697
+ scope . selected = [ { id : 10 , label : 'ten' } ] ;
691
698
} ) ;
692
699
693
700
expect ( element . val ( ) ) . toEqual ( [ '10' ] ) ;
694
701
695
- // Update the properties on the
702
+ // Update the properties on the object in the selected array, rather than replacing the whole object
696
703
scope . $apply ( function ( ) {
697
704
scope . selected [ 0 ] . id = 20 ;
698
705
scope . selected [ 0 ] . label = 'new twenty' ;
699
706
} ) ;
700
707
708
+ // The value of the select should change since the id property changed
701
709
expect ( element . val ( ) ) . toEqual ( [ '20' ] ) ;
710
+
711
+ // But the label of the selected option does not change
712
+ var option = element . find ( 'option' ) . eq ( 1 ) ;
713
+ expect ( option . prop ( 'selected' ) ) . toEqual ( true ) ;
714
+ expect ( option . text ( ) ) . toEqual ( 'twenty' ) ; // not 'new twenty'
702
715
} ) ;
703
716
704
717
0 commit comments