I've created custom directive to populate auto dash. Here is full custom directive code in stackblitz. May i know how to test following lines from mask.ts in jasmine (unit test)?
mask.ts
@HostListener('input', ['$event'])
onKeyDown(event: KeyboardEvent) {
const input = event.target as HTMLInputElement;
let trimmed = input.value.replace(/\s+/g, '');
mask.spec.ts
@Component({
template: `
<input type="text" dobMask />
`,
})
class TestdobMaskComponent {}
describe('dobMask', () => {
let component: TestdobMaskComponent;
let fixture: ComponentFixture<TestdobMaskComponent>;
let inputEl: DebugElement;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestdobMaskComponent],
});
fixture = TestBed.createComponent(TestdobMaskComponent);
component = fixture.componentInstance;
inputEl = fixture.debugElement.query(By.css('input'));
});
it('should auto populate dash when reach 6 characters', () => {
const input = inputEl.nativeElement as HTMLInputElement;
});
});