I have this html code in my component
<mat-radio-group aria-label="Select an option" [(ngModel)]="searchType" (change)="changeSearchType()" class="form-row">
<mat-radio-button [value]="searchByUserType" class="mr-5 max-w-1/2 flex-1">{{'CONTENT.Search by User' | translate
}}</mat-radio-button>
<mat-radio-button [value]="searchByRegType" class="max-w-1/2 flex-1">{{'CONTENT.Search by Reg' | translate
}}</mat-radio-button>
</mat-radio-group>
and this test
it('should select the correct value for the radio buttons', () => {
const radioGroupDebugElement = fixture.debugElement.query(By.css('mat-radio-group'));
const radioButtons = radioGroupDebugElement.queryAll(By.css('mat-radio-button'));
// Simulate user selecting the first radio button
radioButtons[0].nativeElement.click();
console.log(radioButtons[0].nativeElement.value);
fixture.detectChanges();
// Manually dispatch a change event
radioGroupDebugElement.nativeElement.dispatchEvent(new Event('change'));
fixture.detectChanges();
expect(component.searchType).toBe(component.searchByUserType);
// Simulate user selecting the second radio button
radioButtons[1].nativeElement.click();
fixture.detectChanges();
// Manually dispatch a change event
radioGroupDebugElement.nativeElement.dispatchEvent(new Event('change'));
fixture.detectChanges();
expect(component.searchType).toBe(component.searchByRegType);
});
and I'm getting failed tests with "Expected undefined to be 'SearchByUser'." and "Expected undefined to be 'SearchByReg'."
The value of the radio button is not captured in the test.
What am I missing here?
Thanks