I have a custom matcher, very basic, and I don’t know how to write a unit test for this (minimum coverage is mandatory on the project).
Should I mock completely FormControl and Form to test each value of submitted/invalid/dirty/touched?
That looks like a lot of mocking, is there anything in Angular to ease that kind of test?
/**
* Error when invalid control is dirty, touched, or submitted.
*/
export class ShowOnChangeErrorStateMatcher implements ErrorStateMatcher {
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
if (!control) {
return false;
}
const isSubmitted = form?.submitted ?? false;
return control.invalid && (control.dirty || control.touched || isSubmitted);
}
}