@@ -663,7 +663,7 @@ describe('select', function() {
663
663
} ) ;
664
664
665
665
666
- describe ( 'trackBy' , function ( ) {
666
+ describe ( 'trackBy expression ' , function ( ) {
667
667
beforeEach ( function ( ) {
668
668
scope . arr = [ { id : 10 , label : 'ten' } , { id :20 , label : 'twenty' } ] ;
669
669
scope . obj = { '10' : { score : 10 , label : 'ten' } , '20' : { score : 20 , label : 'twenty' } } ;
@@ -761,173 +761,22 @@ describe('select', function() {
761
761
} ) ;
762
762
763
763
764
- describe ( 'selectAs+trackBy' , function ( ) {
764
+ describe ( 'selectAs+trackBy expression ' , function ( ) {
765
765
beforeEach ( function ( ) {
766
766
scope . arr = [ { id : 10 , label : 'ten' } , { id :'20' , label : 'twenty' } ] ;
767
767
scope . obj = { '10' : { score : 10 , label : 'ten' } , '20' : { score : 20 , label : 'twenty' } } ;
768
768
} ) ;
769
769
770
770
771
- it ( 'should bind selectAs expression result to scope (array&single)' , function ( ) {
772
- createSelect ( {
773
- 'ng-model' : 'selected' ,
774
- 'ng-options' : 'item.id as item.name for item in values track by item.id'
775
- } ) ;
776
-
777
- scope . $apply ( function ( ) {
778
- scope . values = [ { id : 10 , name : 'A' } , { id : 20 , name : 'B' } ] ;
779
- scope . selected = 10 ;
780
- } ) ;
781
- expect ( element . val ( ) ) . toEqual ( '0' ) ;
782
-
783
- scope . $apply ( function ( ) {
784
- scope . selected = 20 ;
785
- } ) ;
786
- expect ( element . val ( ) ) . toEqual ( '1' ) ;
787
-
788
- element . val ( '0' ) ;
789
- browserTrigger ( element , 'change' ) ;
790
- expect ( scope . selected ) . toBe ( 10 ) ;
791
- } ) ;
792
-
793
-
794
- it ( 'should bind selectAs expression result to scope (array&multiple)' , function ( ) {
795
- createSelect ( {
796
- 'ng-model' : 'selected' ,
797
- 'multiple' : true ,
798
- 'ng-options' : 'item.id as item.name for item in values track by item.id'
799
- } ) ;
800
-
801
- scope . $apply ( function ( ) {
802
- scope . values = [ { id : 10 , name : 'A' } , { id : 20 , name : 'B' } ] ;
803
- scope . selected = [ 10 ] ;
804
- } ) ;
805
- expect ( element . val ( ) ) . toEqual ( [ '0' ] ) ;
806
-
807
- scope . $apply ( function ( ) {
808
- scope . selected = [ 20 ] ;
809
- } ) ;
810
- expect ( element . val ( ) ) . toEqual ( [ '1' ] ) ;
811
-
812
- element . children ( 0 ) . attr ( 'selected' , 'selected' ) ;
813
- element . children ( 1 ) . attr ( 'selected' , 'selected' ) ;
814
- browserTrigger ( element , 'change' ) ;
815
- expect ( scope . selected ) . toEqual ( [ 10 , 20 ] ) ;
816
- } ) ;
817
-
818
-
819
- it ( 'should bind selectAs expression result to scope (object&single)' , function ( ) {
820
- createSelect ( {
821
- 'ng-model' : 'selected' ,
822
- 'ng-options' : 'value.score as value.label for (key, value) in obj track by value.score'
823
- } ) ;
824
-
825
- scope . $apply ( function ( ) {
826
- scope . selected = 10 ;
827
- } ) ;
828
- expect ( element . val ( ) ) . toEqual ( '10' ) ;
829
-
830
- scope . $apply ( function ( ) {
831
- scope . selected = 20 ;
832
- } ) ;
833
- expect ( element . val ( ) ) . toEqual ( '20' ) ;
834
-
835
- element . val ( '10' ) ;
836
- browserTrigger ( element , 'change' ) ;
837
- expect ( scope . selected ) . toBe ( 10 ) ;
838
- } ) ;
839
-
840
-
841
- it ( 'should bind selectAs expression result to scope (object&multiple)' , function ( ) {
842
- createSelect ( {
843
- 'ng-model' : 'selected' ,
844
- 'multiple' : true ,
845
- 'ng-options' : 'value.score as value.label for (key, value) in obj track by value.score'
846
- } ) ;
847
-
848
- scope . $apply ( function ( ) {
849
- scope . selected = [ 10 ] ;
850
- } ) ;
851
- expect ( element . val ( ) ) . toEqual ( [ '10' ] ) ;
852
-
853
- scope . $apply ( function ( ) {
854
- scope . selected = [ 20 ] ;
855
- } ) ;
856
- expect ( element . val ( ) ) . toEqual ( [ '20' ] ) ;
857
-
858
- element . find ( 'option' ) [ 0 ] . selected = 'selected' ;
859
- browserTrigger ( element , 'change' ) ;
860
- expect ( scope . selected ) . toEqual ( [ 10 , 20 ] ) ;
861
- } ) ;
862
-
863
-
864
- it ( 'should correctly assign model if track & select expressions differ (array&single)' , function ( ) {
865
- createSelect ( {
866
- 'ng-model' : 'selected' ,
867
- 'ng-options' : 'item.label as item.label for item in arr track by item.id'
868
- } ) ;
869
-
870
- scope . $apply ( function ( ) {
871
- scope . selected = 'ten' ;
872
- } ) ;
873
- expect ( element . val ( ) ) . toBe ( '0' ) ;
874
-
875
- element . val ( '1' ) ;
876
- browserTrigger ( element , 'change' ) ;
877
- expect ( scope . selected ) . toBe ( 'twenty' ) ;
878
- } ) ;
879
-
880
-
881
- it ( 'should correctly assign model if track & select expressions differ (array&multiple)' , function ( ) {
882
- createSelect ( {
883
- 'ng-model' : 'selected' ,
884
- 'multiple' : true ,
885
- 'ng-options' : 'item.label as item.label for item in arr track by item.id'
886
- } ) ;
887
-
888
- scope . $apply ( function ( ) {
889
- scope . selected = [ 'ten' ] ;
890
- } ) ;
891
- expect ( element . val ( ) ) . toEqual ( [ '0' ] ) ;
892
-
893
- element . find ( 'option' ) [ 1 ] . selected = 'selected' ;
894
- browserTrigger ( element , 'change' ) ;
895
- expect ( scope . selected ) . toEqual ( [ 'ten' , 'twenty' ] ) ;
896
- } ) ;
897
-
771
+ it ( 'should throw a helpful minerr' , function ( ) {
772
+ expect ( function ( ) {
898
773
899
- it ( 'should correctly assign model if track & select expressions differ (object&single)' , function ( ) {
900
- createSelect ( {
901
- 'ng-model' : 'selected' ,
902
- 'ng-options' : 'val.label as val.label for (key, val) in obj track by val.score'
903
- } ) ;
904
-
905
- scope . $apply ( function ( ) {
906
- scope . selected = 'ten' ;
907
- } ) ;
908
- expect ( element . val ( ) ) . toBe ( '10' ) ;
909
-
910
- element . val ( '20' ) ;
911
- browserTrigger ( element , 'change' ) ;
912
- expect ( scope . selected ) . toBe ( 'twenty' ) ;
913
- } ) ;
914
-
915
-
916
- it ( 'should correctly assign model if track & select expressions differ (object&multiple)' , function ( ) {
917
- createSelect ( {
918
- 'ng-model' : 'selected' ,
919
- 'multiple' : true ,
920
- 'ng-options' : 'val.label as val.label for (key, val) in obj track by val.score'
921
- } ) ;
922
-
923
- scope . $apply ( function ( ) {
924
- scope . selected = [ 'ten' ] ;
925
- } ) ;
926
- expect ( element . val ( ) ) . toEqual ( [ '10' ] ) ;
774
+ createSelect ( {
775
+ 'ng-model' : 'selected' ,
776
+ 'ng-options' : 'item.id as item.name for item in values track by item.id'
777
+ } ) ;
927
778
928
- element . find ( 'option' ) [ 1 ] . selected = 'selected' ;
929
- browserTrigger ( element , 'change' ) ;
930
- expect ( scope . selected ) . toEqual ( [ 'ten' , 'twenty' ] ) ;
779
+ } ) . toThrowMinErr ( 'ngOptions' , 'trkslct' , "Comprehension expression cannot contain both selectAs 'item.id' and trackBy 'item.id' expressions." ) ;
931
780
} ) ;
932
781
} ) ;
933
782
@@ -1264,7 +1113,7 @@ describe('select', function() {
1264
1113
it ( 'should bind to scope value and track/identify objects' , function ( ) {
1265
1114
createSelect ( {
1266
1115
'ng-model' : 'selected' ,
1267
- 'ng-options' : 'item as item .name for item in values track by item.id'
1116
+ 'ng-options' : 'item.name for item in values track by item.id'
1268
1117
} ) ;
1269
1118
1270
1119
scope . $apply ( function ( ) {
0 commit comments