@@ -657,48 +657,61 @@ describe('ngOptions', function() {
657657 } ) ;
658658
659659
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 ( ) {
661661 createSelect ( {
662662 'ng-model' : 'selected' ,
663663 'ng-options' : 'item.label for item in arr track by item.id'
664664 } ) ;
665665
666666 scope . $apply ( function ( ) {
667- scope . selected = { id : 10 , label : 'new ten' } ;
667+ scope . selected = { id : 10 , label : 'ten' } ;
668668 } ) ;
669669
670- expect ( element . val ( ) ) . toBe ( '10' ) ;
670+ expect ( element . val ( ) ) . toEqual ( '10' ) ;
671671
672- // Update the properties on the
672+ // Update the properties on the selected object, rather than replacing the whole object
673673 scope . $apply ( function ( ) {
674674 scope . selected . id = 20 ;
675675 scope . selected . label = 'new twenty' ;
676676 } ) ;
677677
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'
679685 } ) ;
680686
681687
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 ( ) {
683690 createSelect ( {
684691 'ng-model' : 'selected' ,
685692 'multiple' : true ,
686693 'ng-options' : 'item.label for item in arr track by item.id'
687694 } ) ;
688695
689696 scope . $apply ( function ( ) {
690- scope . selected = [ { id : 10 , label : 'new ten' } ] ;
697+ scope . selected = [ { id : 10 , label : 'ten' } ] ;
691698 } ) ;
692699
693700 expect ( element . val ( ) ) . toEqual ( [ '10' ] ) ;
694701
695- // Update the properties on the
702+ // Update the properties on the object in the selected array, rather than replacing the whole object
696703 scope . $apply ( function ( ) {
697704 scope . selected [ 0 ] . id = 20 ;
698705 scope . selected [ 0 ] . label = 'new twenty' ;
699706 } ) ;
700707
708+ // The value of the select should change since the id property changed
701709 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'
702715 } ) ;
703716
704717
0 commit comments