@@ -656,7 +656,74 @@ describe('ngOptions', function() {
656
656
expect ( options . eq ( 2 ) ) . toEqualTrackedOption ( 20 , 'twenty' ) ;
657
657
} ) ;
658
658
659
-
659
+
660
+ it ( 'should update the selected item when only the properties on the object change (single)' , function ( ) {
661
+ createSelect ( {
662
+ 'ng-model' : 'selected' ,
663
+ 'ng-options' : 'item.label for item in arr track by item.id'
664
+ } ) ;
665
+
666
+ scope . $apply ( function ( ) {
667
+ scope . selected = { id : 10 , label : 'new ten' } ;
668
+ } ) ;
669
+
670
+ expect ( element . val ( ) ) . toBe ( '10' ) ;
671
+
672
+ // Update the properties on the
673
+ scope . $apply ( function ( ) {
674
+ scope . selected . id = 20 ;
675
+ scope . selected . label = 'new twenty' ;
676
+ } ) ;
677
+
678
+ expect ( element . val ( ) ) . toBe ( '20' ) ;
679
+ } ) ;
680
+
681
+
682
+ it ( 'should update the selected item when only the properties on the object change (multi)' , function ( ) {
683
+ createSelect ( {
684
+ 'ng-model' : 'selected' ,
685
+ 'multiple' : true ,
686
+ 'ng-options' : 'item.label for item in arr track by item.id'
687
+ } ) ;
688
+
689
+ scope . $apply ( function ( ) {
690
+ scope . selected = [ { id : 10 , label : 'new ten' } ] ;
691
+ } ) ;
692
+
693
+ expect ( element . val ( ) ) . toEqual ( [ '10' ] ) ;
694
+
695
+ // Update the properties on the
696
+ scope . $apply ( function ( ) {
697
+ scope . selected [ 0 ] . id = 20 ;
698
+ scope . selected [ 0 ] . label = 'new twenty' ;
699
+ } ) ;
700
+
701
+ expect ( element . val ( ) ) . toEqual ( [ '20' ] ) ;
702
+ } ) ;
703
+
704
+
705
+ it ( 'should prevent changes to the selected object from modifying the options objects (single)' , function ( ) {
706
+
707
+ createSelect ( {
708
+ 'ng-model' : 'selected' ,
709
+ 'ng-options' : 'item.label for item in arr track by item.id'
710
+ } ) ;
711
+
712
+ element . val ( '10' ) ;
713
+ browserTrigger ( element , 'change' ) ;
714
+
715
+ expect ( scope . selected ) . toEqual ( scope . arr [ 0 ] ) ;
716
+
717
+ scope . $apply ( function ( ) {
718
+ scope . selected . id = 20 ;
719
+ } ) ;
720
+
721
+ expect ( scope . selected ) . not . toEqual ( scope . arr [ 0 ] ) ;
722
+ expect ( element . val ( ) ) . toEqual ( '20' ) ;
723
+ expect ( scope . arr ) . toEqual ( [ { id : 10 , label : 'ten' } , { id :20 , label : 'twenty' } ] ) ;
724
+ } ) ;
725
+
726
+
660
727
it ( 'should preserve value even when reference has changed (single&array)' , function ( ) {
661
728
createSelect ( {
662
729
'ng-model' : 'selected' ,
@@ -719,7 +786,7 @@ describe('ngOptions', function() {
719
786
expect ( element . val ( ) ) . toBe ( '10' ) ;
720
787
721
788
setSelectValue ( element , 1 ) ;
722
- expect ( scope . selected ) . toBe ( scope . obj [ '2' ] ) ;
789
+ expect ( scope . selected ) . toEqual ( scope . obj [ '2' ] ) ;
723
790
} ) ;
724
791
725
792
@@ -798,7 +865,7 @@ describe('ngOptions', function() {
798
865
799
866
element . val ( '10' ) ;
800
867
browserTrigger ( element , 'change' ) ;
801
- expect ( scope . selected ) . toBe ( scope . arr [ 0 ] . subItem ) ;
868
+ expect ( scope . selected ) . toEqual ( scope . arr [ 0 ] . subItem ) ;
802
869
803
870
// Now reload the array
804
871
scope . $apply ( function ( ) {
@@ -1352,7 +1419,7 @@ describe('ngOptions', function() {
1352
1419
scope . values . pop ( ) ;
1353
1420
} ) ;
1354
1421
1355
- expect ( element . val ( ) ) . toEqualUnknownValue ( ) ;
1422
+ expect ( element . val ( ) ) . toEqual ( '' ) ;
1356
1423
expect ( scope . selected ) . toEqual ( null ) ;
1357
1424
1358
1425
// Check after model change
@@ -1366,7 +1433,7 @@ describe('ngOptions', function() {
1366
1433
scope . values . pop ( ) ;
1367
1434
} ) ;
1368
1435
1369
- expect ( element . val ( ) ) . toEqualUnknownValue ( ) ;
1436
+ expect ( element . val ( ) ) . toEqual ( '' ) ;
1370
1437
expect ( scope . selected ) . toEqual ( null ) ;
1371
1438
} ) ;
1372
1439
0 commit comments