To test your custom validator, create an instance of the control and input your validation function. Then set a value and check the expected outcome.
See below for an illustration:
let formControl: FormControl;
describe('Custom Validator Test: ', () => {
beforeAll(() => {
formControl = new FormControl('', [customValidator]);
});
it('should pass validation', () => {
formControl.setValue('valid input');
expect(formControl.valid).toBe(true); // valid input
formControl.setValue('invalid input');
expect(formControl.valid).toBe(false); // invalid input
});
});