@@ -145,7 +145,7 @@ describe('radio harness', () => {
145
145
describe ( 'MatRadioButtonHarness' , ( ) => {
146
146
it ( 'should load all radio-button harnesses' , async ( ) => {
147
147
const radios = await loader . getAllHarnesses ( MatRadioButtonHarness ) ;
148
- expect ( radios . length ) . toBe ( 9 ) ;
148
+ expect ( radios . length ) . toBe ( 10 ) ;
149
149
} ) ;
150
150
151
151
it ( 'should load radio-button with exact label' , async ( ) => {
@@ -267,10 +267,25 @@ describe('radio harness', () => {
267
267
expect ( await radioButton . isChecked ( ) ) . toBe ( true ) ;
268
268
} ) ;
269
269
270
- it ( 'should get required state' , async ( ) => {
270
+ // radios with group should not contain required attribute as group itself is marked if its
271
+ // required or not, see #30399
272
+ it ( 'should have falsy required state if used with MatRadioGroup' , async ( ) => {
273
+ const radioButton = await loader . getHarness (
274
+ MatRadioButtonHarness . with ( { selector : '#required-radio-inside-group' } ) ,
275
+ ) ;
276
+ expect ( await radioButton . isRequired ( ) ) . toBe ( false ) ;
277
+ } ) ;
278
+
279
+ it ( 'should set required state of radio without group' , async ( ) => {
271
280
const radioButton = await loader . getHarness (
272
281
MatRadioButtonHarness . with ( { selector : '#required-radio' } ) ,
273
282
) ;
283
+ expect ( await radioButton . isRequired ( ) ) . toBe ( false ) ;
284
+
285
+ fixture . componentInstance . standaloneRequiredRadio = true ;
286
+ fixture . changeDetectorRef . markForCheck ( ) ;
287
+ fixture . detectChanges ( ) ;
288
+
274
289
expect ( await radioButton . isRequired ( ) ) . toBe ( true ) ;
275
290
} ) ;
276
291
} ) ;
@@ -302,11 +317,15 @@ describe('radio harness', () => {
302
317
303
318
304
319
<mat-radio-group [id]="secondGroupId" [name]="secondGroupId + '-name'">
305
- <mat-radio-button id="required-radio" required [value]="true">
320
+ <mat-radio-button id="required-radio-inside-group " required [value]="true">
306
321
Accept terms of conditions
307
322
</mat-radio-button>
308
323
</mat-radio-group>
309
324
325
+ <mat-radio-button id="required-radio" [required]="standaloneRequiredRadio" [value]="true">
326
+ Accept terms of conditions
327
+ </mat-radio-button>
328
+
310
329
<mat-radio-group [name]="thirdGroupName">
311
330
<mat-radio-button [value]="true">First</mat-radio-button>
312
331
<mat-radio-button [value]="false" [name]="thirdGroupButtonName"></mat-radio-button>
@@ -321,4 +340,5 @@ class MultipleRadioButtonsHarnessTest {
321
340
secondGroupId = 'my-group-2' ;
322
341
thirdGroupName : string = 'third-group-name' ;
323
342
thirdGroupButtonName : string | undefined = undefined ;
343
+ standaloneRequiredRadio = false ;
324
344
}
0 commit comments