1
- import { dispatchFakeEvent } from '../.. /cdk/testing/private' ;
1
+ import { dispatchFakeEvent } from '@angular /cdk/testing/private' ;
2
2
import { ChangeDetectionStrategy , Component , DebugElement , Type } from '@angular/core' ;
3
3
import { ComponentFixture , fakeAsync , flush , flushMicrotasks , TestBed } from '@angular/core/testing' ;
4
4
import { ThemePalette } from '@angular/material/core' ;
@@ -10,15 +10,15 @@ import {
10
10
MatCheckbox ,
11
11
MatCheckboxChange ,
12
12
MatCheckboxModule ,
13
+ MatCheckboxRequiredValidator ,
13
14
} from './index' ;
14
15
15
16
describe ( 'MDC-based MatCheckbox' , ( ) => {
16
17
let fixture : ComponentFixture < any > ;
17
18
18
- function createComponent < T > ( componentType : Type < T > , extraDeclarations : Type < any > [ ] = [ ] ) {
19
+ function createComponent < T > ( componentType : Type < T > ) {
19
20
TestBed . configureTestingModule ( {
20
- imports : [ MatCheckboxModule , FormsModule , ReactiveFormsModule ] ,
21
- declarations : [ componentType , ...extraDeclarations ] ,
21
+ imports : [ MatCheckboxModule , FormsModule , ReactiveFormsModule , componentType ] ,
22
22
} ) . compileComponents ( ) ;
23
23
24
24
return TestBed . createComponent < T > ( componentType ) ;
@@ -526,8 +526,7 @@ describe('MDC-based MatCheckbox', () => {
526
526
beforeEach ( ( ) => {
527
527
TestBed . resetTestingModule ( ) ;
528
528
TestBed . configureTestingModule ( {
529
- imports : [ MatCheckboxModule , FormsModule , ReactiveFormsModule ] ,
530
- declarations : [ SingleCheckbox ] ,
529
+ imports : [ MatCheckboxModule , FormsModule , ReactiveFormsModule , SingleCheckbox ] ,
531
530
providers : [ { provide : MAT_CHECKBOX_DEFAULT_OPTIONS , useValue : { clickAction : 'check' } } ] ,
532
531
} ) ;
533
532
@@ -558,8 +557,7 @@ describe('MDC-based MatCheckbox', () => {
558
557
beforeEach ( ( ) => {
559
558
TestBed . resetTestingModule ( ) ;
560
559
TestBed . configureTestingModule ( {
561
- imports : [ MatCheckboxModule , FormsModule , ReactiveFormsModule ] ,
562
- declarations : [ SingleCheckbox ] ,
560
+ imports : [ MatCheckboxModule , FormsModule , ReactiveFormsModule , SingleCheckbox ] ,
563
561
providers : [ { provide : MAT_CHECKBOX_DEFAULT_OPTIONS , useValue : { clickAction : 'noop' } } ] ,
564
562
} ) ;
565
563
@@ -1022,8 +1020,7 @@ describe('MatCheckboxDefaultOptions', () => {
1022
1020
describe ( 'when MAT_CHECKBOX_DEFAULT_OPTIONS overridden' , ( ) => {
1023
1021
function configure ( defaults : MatCheckboxDefaultOptions ) {
1024
1022
TestBed . configureTestingModule ( {
1025
- imports : [ MatCheckboxModule , FormsModule ] ,
1026
- declarations : [ SingleCheckbox , SingleCheckbox ] ,
1023
+ imports : [ MatCheckboxModule , FormsModule , SingleCheckbox , SingleCheckbox ] ,
1027
1024
providers : [ { provide : MAT_CHECKBOX_DEFAULT_OPTIONS , useValue : defaults } ] ,
1028
1025
} ) ;
1029
1026
@@ -1078,6 +1075,8 @@ describe('MatCheckboxDefaultOptions', () => {
1078
1075
Simple checkbox
1079
1076
</mat-checkbox>
1080
1077
</div>` ,
1078
+ standalone : true ,
1079
+ imports : [ MatCheckbox ] ,
1081
1080
} )
1082
1081
class SingleCheckbox {
1083
1082
labelPos : 'before' | 'after' = 'after' ;
@@ -1100,6 +1099,8 @@ class SingleCheckbox {
1100
1099
@Component ( {
1101
1100
template : `<mat-checkbox [required]="isRequired" [(ngModel)]="isGood"
1102
1101
[disabled]="isDisabled">Be good</mat-checkbox>` ,
1102
+ standalone : true ,
1103
+ imports : [ MatCheckbox , MatCheckboxRequiredValidator , FormsModule ] ,
1103
1104
} )
1104
1105
class CheckboxWithNgModel {
1105
1106
isGood : boolean = false ;
@@ -1110,6 +1111,8 @@ class CheckboxWithNgModel {
1110
1111
@Component ( {
1111
1112
template : `<mat-checkbox [required]="isRequired" [(ngModel)]="isGood">Be good</mat-checkbox>` ,
1112
1113
changeDetection : ChangeDetectionStrategy . OnPush ,
1114
+ standalone : true ,
1115
+ imports : [ MatCheckbox , FormsModule ] ,
1113
1116
} )
1114
1117
class CheckboxWithNgModelAndOnPush extends CheckboxWithNgModel { }
1115
1118
@@ -1119,6 +1122,8 @@ class CheckboxWithNgModelAndOnPush extends CheckboxWithNgModel {}
1119
1122
<mat-checkbox>Option 1</mat-checkbox>
1120
1123
<mat-checkbox>Option 2</mat-checkbox>
1121
1124
` ,
1125
+ standalone : true ,
1126
+ imports : [ MatCheckbox ] ,
1122
1127
} )
1123
1128
class MultipleCheckboxes { }
1124
1129
@@ -1129,53 +1134,87 @@ class MultipleCheckboxes {}
1129
1134
[tabIndex]="customTabIndex"
1130
1135
[disabled]="isDisabled">
1131
1136
</mat-checkbox>` ,
1137
+ standalone : true ,
1138
+ imports : [ MatCheckbox ] ,
1132
1139
} )
1133
1140
class CheckboxWithTabIndex {
1134
1141
customTabIndex : number = 7 ;
1135
1142
isDisabled : boolean = false ;
1136
1143
}
1137
1144
1138
1145
/** Simple test component with an aria-label set. */
1139
- @Component ( { template : `<mat-checkbox aria-label="Super effective"></mat-checkbox>` } )
1146
+ @Component ( {
1147
+ template : `<mat-checkbox aria-label="Super effective"></mat-checkbox>` ,
1148
+ standalone : true ,
1149
+ imports : [ MatCheckbox ] ,
1150
+ } )
1140
1151
class CheckboxWithAriaLabel { }
1141
1152
1142
1153
/** Simple test component with an aria-label set. */
1143
- @Component ( { template : `<mat-checkbox aria-labelledby="some-id"></mat-checkbox>` } )
1154
+ @Component ( {
1155
+ template : `<mat-checkbox aria-labelledby="some-id"></mat-checkbox>` ,
1156
+ standalone : true ,
1157
+ imports : [ MatCheckbox ] ,
1158
+ } )
1144
1159
class CheckboxWithAriaLabelledby { }
1145
1160
1146
1161
/** Simple test component with an aria-describedby set. */
1147
1162
@Component ( {
1148
1163
template : `<mat-checkbox aria-describedby="some-id"></mat-checkbox>` ,
1164
+ standalone : true ,
1165
+ imports : [ MatCheckbox ] ,
1149
1166
} )
1150
1167
class CheckboxWithAriaDescribedby { }
1151
1168
1152
1169
/** Simple test component with name attribute */
1153
- @Component ( { template : `<mat-checkbox name="test-name"></mat-checkbox>` } )
1170
+ @Component ( {
1171
+ template : `<mat-checkbox name="test-name"></mat-checkbox>` ,
1172
+ standalone : true ,
1173
+ imports : [ MatCheckbox ] ,
1174
+ } )
1154
1175
class CheckboxWithNameAttribute { }
1155
1176
1156
1177
/** Simple test component with change event */
1157
- @Component ( { template : `<mat-checkbox (change)="lastEvent = $event"></mat-checkbox>` } )
1178
+ @Component ( {
1179
+ template : `<mat-checkbox (change)="lastEvent = $event"></mat-checkbox>` ,
1180
+ standalone : true ,
1181
+ imports : [ MatCheckbox ] ,
1182
+ } )
1158
1183
class CheckboxWithChangeEvent {
1159
1184
lastEvent : MatCheckboxChange ;
1160
1185
}
1161
1186
1162
1187
/** Test component with reactive forms */
1163
- @Component ( { template : `<mat-checkbox [formControl]="formControl"></mat-checkbox>` } )
1188
+ @Component ( {
1189
+ template : `<mat-checkbox [formControl]="formControl"></mat-checkbox>` ,
1190
+ standalone : true ,
1191
+ imports : [ MatCheckbox , ReactiveFormsModule ] ,
1192
+ } )
1164
1193
class CheckboxWithFormControl {
1165
1194
formControl = new FormControl ( false ) ;
1166
1195
}
1167
1196
1168
1197
/** Test component without label */
1169
- @Component ( { template : `<mat-checkbox>{{ label }}</mat-checkbox>` } )
1198
+ @Component ( {
1199
+ template : `<mat-checkbox>{{ label }}</mat-checkbox>` ,
1200
+ standalone : true ,
1201
+ imports : [ MatCheckbox ] ,
1202
+ } )
1170
1203
class CheckboxWithoutLabel {
1171
1204
label : string ;
1172
1205
}
1173
1206
1174
1207
/** Test component with the native tabindex attribute. */
1175
- @Component ( { template : `<mat-checkbox tabindex="5"></mat-checkbox>` } )
1208
+ @Component ( {
1209
+ template : `<mat-checkbox tabindex="5"></mat-checkbox>` ,
1210
+ standalone : true ,
1211
+ imports : [ MatCheckbox ] ,
1212
+ } )
1176
1213
class CheckboxWithTabindexAttr { }
1177
1214
1178
1215
@Component ( {
1179
1216
template : `<mat-checkbox aria-label="Checkbox" aria-labelledby="something"></mat-checkbox>` ,
1217
+ standalone : true ,
1218
+ imports : [ MatCheckbox ] ,
1180
1219
} )
1181
1220
class CheckboxWithStaticAriaAttributes { }
0 commit comments