@@ -751,7 +751,7 @@ describe('ngOptions', function() {
751
751
} ) ;
752
752
753
753
754
- it ( 'should not select disabled options when model changes' , function ( ) {
754
+ it ( 'should select disabled options when model changes' , function ( ) {
755
755
scope . options = [
756
756
{ name : 'white' , value : '#FFFFFF' } ,
757
757
{ name : 'one' , value : 1 , unavailable : true } ,
@@ -772,11 +772,14 @@ describe('ngOptions', function() {
772
772
scope . $apply ( 'selected = 1' ) ;
773
773
options = element . find ( 'option' ) ;
774
774
775
- expect ( element . val ( ) ) . toEqualUnknownValue ( '?' ) ;
776
- expect ( options . length ) . toEqual ( 5 ) ;
777
- expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
775
+ // jQuery returns null for val() when the option is disabled, see
776
+ // https://bugs.jquery.com/ticket/13097
777
+ expect ( element [ 0 ] . value ) . toBe ( 'number:1' ) ;
778
+ expect ( options . length ) . toEqual ( 4 ) ;
779
+ expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
780
+ expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
778
781
expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
779
- expect ( options . eq ( 4 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
782
+ expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
780
783
} ) ;
781
784
782
785
@@ -796,11 +799,14 @@ describe('ngOptions', function() {
796
799
scope . $apply ( 'selected = 1' ) ;
797
800
var options = element . find ( 'option' ) ;
798
801
799
- expect ( element . val ( ) ) . toEqualUnknownValue ( '?' ) ;
800
- expect ( options . length ) . toEqual ( 5 ) ;
801
- expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
802
+ // jQuery returns null for val() when the option is disabled, see
803
+ // https://bugs.jquery.com/ticket/13097
804
+ expect ( element [ 0 ] . value ) . toBe ( 'number:1' ) ;
805
+ expect ( options . length ) . toEqual ( 4 ) ;
806
+ expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
807
+ expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
802
808
expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
803
- expect ( options . eq ( 4 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
809
+ expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
804
810
805
811
// Now enable that option
806
812
scope . $apply ( function ( ) {
@@ -841,7 +847,7 @@ describe('ngOptions', function() {
841
847
} ) ;
842
848
843
849
844
- it ( 'should not select disabled options when model changes' , function ( ) {
850
+ it ( 'should select disabled options when model changes' , function ( ) {
845
851
scope . options = [
846
852
{ name : 'a' , value : 0 } ,
847
853
{ name : 'b' , value : 1 , unavailable : true } ,
@@ -866,14 +872,14 @@ describe('ngOptions', function() {
866
872
scope . $apply ( 'selected = [1,3]' ) ;
867
873
options = element . find ( 'option' ) ;
868
874
expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
869
- expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
875
+ expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
870
876
expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
871
877
expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
872
878
873
879
// Now only select the disabled option
874
880
scope . $apply ( 'selected = [1]' ) ;
875
881
expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
876
- expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
882
+ expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
877
883
expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
878
884
expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
879
885
} ) ;
@@ -897,7 +903,7 @@ describe('ngOptions', function() {
897
903
var options = element . find ( 'option' ) ;
898
904
899
905
expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
900
- expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
906
+ expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
901
907
expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
902
908
expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
903
909
@@ -2515,37 +2521,6 @@ describe('ngOptions', function() {
2515
2521
expect ( element . find ( 'option' ) [ 1 ] . selected ) . toBeTruthy ( ) ;
2516
2522
} ) ;
2517
2523
2518
- it ( 'should not write disabled selections from model' , function ( ) {
2519
- scope . selected = [ 30 ] ;
2520
- scope . options = [
2521
- { name : 'white' , value : '#FFFFFF' } ,
2522
- { name : 'one' , value : 1 , unavailable : true } ,
2523
- { name : 'notTrue' , value : false } ,
2524
- { name : 'thirty' , value : 30 , unavailable : false }
2525
- ] ;
2526
- createSelect ( {
2527
- 'ng-options' : 'o.value as o.name disable when o.unavailable for o in options' ,
2528
- 'ng-model' : 'selected' ,
2529
- 'multiple' : true
2530
- } ) ;
2531
-
2532
- var options = element . find ( 'option' ) ;
2533
-
2534
- expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2535
- expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2536
- expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2537
- expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
2538
-
2539
- scope . $apply ( function ( ) {
2540
- scope . selected . push ( 1 ) ;
2541
- } ) ;
2542
-
2543
- expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2544
- expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2545
- expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2546
- expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
2547
- } ) ;
2548
-
2549
2524
2550
2525
it ( 'should update model on change' , function ( ) {
2551
2526
createMultiSelect ( ) ;
0 commit comments