@@ -4,13 +4,9 @@ import {TestBed, fakeAsync, tick} from '@angular/core/testing';
4
4
import { FormControl , ReactiveFormsModule } from '@angular/forms' ;
5
5
import { By } from '@angular/platform-browser' ;
6
6
import { dispatchFakeEvent , dispatchKeyboardEvent , dispatchMouseEvent } from '../testing/private' ;
7
- import { CdkListbox , CdkListboxModule , CdkOption , ListboxValueChangeEvent } from './index' ;
7
+ import { CdkListbox , CdkOption , ListboxValueChangeEvent } from './index' ;
8
8
9
- function setupComponent < T , O = string > ( component : Type < T > , imports : any [ ] = [ ] ) {
10
- TestBed . configureTestingModule ( {
11
- imports : [ CdkListboxModule , ...imports ] ,
12
- declarations : [ component ] ,
13
- } ) ;
9
+ function setupComponent < T , O = string > ( component : Type < T > ) {
14
10
const fixture = TestBed . createComponent ( component ) ;
15
11
fixture . detectChanges ( ) ;
16
12
@@ -861,29 +857,23 @@ describe('CdkOption and CdkListbox', () => {
861
857
862
858
describe ( 'with FormControl' , ( ) => {
863
859
it ( 'should reflect disabled state of the FormControl' , ( ) => {
864
- const { testComponent, fixture, listbox} = setupComponent ( ListboxWithFormControl , [
865
- ReactiveFormsModule ,
866
- ] ) ;
860
+ const { testComponent, fixture, listbox} = setupComponent ( ListboxWithFormControl ) ;
867
861
testComponent . formControl . disable ( ) ;
868
862
fixture . detectChanges ( ) ;
869
863
870
864
expect ( listbox . disabled ) . toBeTrue ( ) ;
871
865
} ) ;
872
866
873
867
it ( 'should update when FormControl value changes' , ( ) => {
874
- const { testComponent, fixture, options} = setupComponent ( ListboxWithFormControl , [
875
- ReactiveFormsModule ,
876
- ] ) ;
868
+ const { testComponent, fixture, options} = setupComponent ( ListboxWithFormControl ) ;
877
869
testComponent . formControl . setValue ( [ 'banana' ] ) ;
878
870
fixture . detectChanges ( ) ;
879
871
880
872
expect ( options [ 2 ] . isSelected ( ) ) . toBeTrue ( ) ;
881
873
} ) ;
882
874
883
875
it ( 'should update FormControl when selection changes' , ( ) => {
884
- const { testComponent, fixture, optionEls} = setupComponent ( ListboxWithFormControl , [
885
- ReactiveFormsModule ,
886
- ] ) ;
876
+ const { testComponent, fixture, optionEls} = setupComponent ( ListboxWithFormControl ) ;
887
877
const spy = jasmine . createSpy ( ) ;
888
878
const subscription = testComponent . formControl . valueChanges . subscribe ( spy ) ;
889
879
fixture . detectChanges ( ) ;
@@ -898,9 +888,7 @@ describe('CdkOption and CdkListbox', () => {
898
888
} ) ;
899
889
900
890
it ( 'should update multi-select listbox when FormControl value changes' , ( ) => {
901
- const { testComponent, fixture, options} = setupComponent ( ListboxWithFormControl , [
902
- ReactiveFormsModule ,
903
- ] ) ;
891
+ const { testComponent, fixture, options} = setupComponent ( ListboxWithFormControl ) ;
904
892
testComponent . isMultiselectable = true ;
905
893
fixture . changeDetectorRef . markForCheck ( ) ;
906
894
fixture . detectChanges ( ) ;
@@ -912,9 +900,7 @@ describe('CdkOption and CdkListbox', () => {
912
900
} ) ;
913
901
914
902
it ( 'should update FormControl when multi-selection listbox changes' , ( ) => {
915
- const { testComponent, fixture, optionEls} = setupComponent ( ListboxWithFormControl , [
916
- ReactiveFormsModule ,
917
- ] ) ;
903
+ const { testComponent, fixture, optionEls} = setupComponent ( ListboxWithFormControl ) ;
918
904
testComponent . isMultiselectable = true ;
919
905
fixture . changeDetectorRef . markForCheck ( ) ;
920
906
fixture . detectChanges ( ) ;
@@ -935,9 +921,7 @@ describe('CdkOption and CdkListbox', () => {
935
921
} ) ;
936
922
937
923
it ( 'should throw when multiple values selected in single-select listbox' , ( ) => {
938
- const { testComponent, fixture} = setupComponent ( ListboxWithFormControl , [
939
- ReactiveFormsModule ,
940
- ] ) ;
924
+ const { testComponent, fixture} = setupComponent ( ListboxWithFormControl ) ;
941
925
942
926
expect ( ( ) => {
943
927
testComponent . formControl . setValue ( [ 'orange' , 'banana' ] ) ;
@@ -946,9 +930,7 @@ describe('CdkOption and CdkListbox', () => {
946
930
} ) ;
947
931
948
932
it ( 'should throw when an invalid value is selected' , ( ) => {
949
- const { testComponent, fixture} = setupComponent ( ListboxWithFormControl , [
950
- ReactiveFormsModule ,
951
- ] ) ;
933
+ const { testComponent, fixture} = setupComponent ( ListboxWithFormControl ) ;
952
934
testComponent . isMultiselectable = true ;
953
935
fixture . changeDetectorRef . markForCheck ( ) ;
954
936
fixture . detectChanges ( ) ;
@@ -961,13 +943,13 @@ describe('CdkOption and CdkListbox', () => {
961
943
962
944
it ( 'should not throw on init with a preselected form control and a dynamic set of options' , ( ) => {
963
945
expect ( ( ) => {
964
- setupComponent ( ListboxWithPreselectedFormControl , [ ReactiveFormsModule ] ) ;
946
+ setupComponent ( ListboxWithPreselectedFormControl ) ;
965
947
} ) . not . toThrow ( ) ;
966
948
} ) ;
967
949
968
950
it ( 'should throw on init if the preselected value is invalid' , ( ) => {
969
951
expect ( ( ) => {
970
- setupComponent ( ListboxWithInvalidPreselectedFormControl , [ ReactiveFormsModule ] ) ;
952
+ setupComponent ( ListboxWithInvalidPreselectedFormControl ) ;
971
953
} ) . toThrowError ( 'Listbox has selected values that do not match any of its options.' ) ;
972
954
} ) ;
973
955
} ) ;
@@ -1000,7 +982,7 @@ describe('CdkOption and CdkListbox', () => {
1000
982
<div cdkOption="peach">Peach</div>
1001
983
</div>
1002
984
` ,
1003
- standalone : false ,
985
+ imports : [ CdkListbox , CdkOption ] ,
1004
986
} )
1005
987
class ListboxWithOptions {
1006
988
changedOption : CdkOption | null ;
@@ -1026,7 +1008,7 @@ class ListboxWithOptions {
1026
1008
1027
1009
@Component ( {
1028
1010
template : `<div cdkListbox></div>` ,
1029
- standalone : false ,
1011
+ imports : [ CdkListbox ] ,
1030
1012
} )
1031
1013
class ListboxWithNoOptions { }
1032
1014
@@ -1042,7 +1024,7 @@ class ListboxWithNoOptions {}
1042
1024
<div cdkOption="peach">Peach</div>
1043
1025
</div>
1044
1026
` ,
1045
- standalone : false ,
1027
+ imports : [ CdkListbox , CdkOption , ReactiveFormsModule ] ,
1046
1028
} )
1047
1029
class ListboxWithFormControl {
1048
1030
formControl = new FormControl ( ) ;
@@ -1058,7 +1040,7 @@ class ListboxWithFormControl {
1058
1040
}
1059
1041
</div>
1060
1042
` ,
1061
- standalone : false ,
1043
+ imports : [ CdkListbox , CdkOption , ReactiveFormsModule ] ,
1062
1044
} )
1063
1045
class ListboxWithPreselectedFormControl {
1064
1046
options = [ 'a' , 'b' , 'c' ] ;
@@ -1073,7 +1055,7 @@ class ListboxWithPreselectedFormControl {
1073
1055
}
1074
1056
</div>
1075
1057
` ,
1076
- standalone : false ,
1058
+ imports : [ CdkListbox , CdkOption , ReactiveFormsModule ] ,
1077
1059
} )
1078
1060
class ListboxWithInvalidPreselectedFormControl {
1079
1061
options = [ 'a' , 'b' , 'c' ] ;
@@ -1089,7 +1071,7 @@ class ListboxWithInvalidPreselectedFormControl {
1089
1071
<li cdkOption="peach" cdkOptionTypeaheadLabel="peach">🍑</li>
1090
1072
</ul>
1091
1073
` ,
1092
- standalone : false ,
1074
+ imports : [ CdkListbox , CdkOption ] ,
1093
1075
} )
1094
1076
class ListboxWithCustomTypeahead { }
1095
1077
@@ -1103,7 +1085,7 @@ class ListboxWithCustomTypeahead {}
1103
1085
<div cdkOption="peach">Peach</div>
1104
1086
</div>
1105
1087
` ,
1106
- standalone : false ,
1088
+ imports : [ CdkListbox , CdkOption ] ,
1107
1089
} )
1108
1090
class ListboxWithBoundValue {
1109
1091
value = [ 'banana' ] ;
@@ -1120,7 +1102,7 @@ class ListboxWithBoundValue {
1120
1102
<div cdkOption="peach">Peach</div>
1121
1103
</div>
1122
1104
` ,
1123
- standalone : false ,
1105
+ imports : [ CdkListbox , CdkOption ] ,
1124
1106
} )
1125
1107
class ListboxWithMultipleBoundValues {
1126
1108
value = [ 'apple' , 'banana' ] ;
@@ -1134,7 +1116,7 @@ class ListboxWithMultipleBoundValues {
1134
1116
}
1135
1117
</div>
1136
1118
` ,
1137
- standalone : false ,
1119
+ imports : [ CdkListbox , CdkOption ] ,
1138
1120
} )
1139
1121
class ListboxWithObjectValues {
1140
1122
fruits = [ { name : 'Apple' } , { name : 'Orange' } , { name : 'Banana' } , { name : 'Peach' } ] ;
0 commit comments