// component functions
...
onFocusoutControl(control, input) {
setTimeout(() => {
control.markAsTouched();
}, 200);
}
// import functions and classes from testing
import {async, ComponentFixture, TestBed, inject, fakeAsync, tick} from '@angular/core/testing';
...
// unit testing
it('should close the input when focused out', fakeAsync(() => {
const control = component.form.controls.emailAddress;
component.onFocusoutControl(control, input);
tick(200);
fixture.whenStable().then( () => {
expect(control.touched).toBeTruthy();
});
}));
Read More