diff --git a/npm/ng-packs/packages/core/src/lib/tests/autofocus.directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/autofocus.directive.spec.ts new file mode 100644 index 0000000000..6a44e0d83e --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/tests/autofocus.directive.spec.ts @@ -0,0 +1,36 @@ +import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; +import { AutofocusDirective } from '../directives/autofocus.directive'; +import { timer } from 'rxjs'; + +describe('AutofocusDirective', () => { + let spectator: SpectatorDirective; + let directive: AutofocusDirective; + let input: HTMLInputElement; + const createDirective = createDirectiveFactory({ + directive: AutofocusDirective, + }); + + beforeEach(() => { + spectator = createDirective('', { + hostProps: {}, + }); + directive = spectator.directive; + input = spectator.query('input'); + }); + + test('should be created', () => { + expect(directive).toBeTruthy(); + }); + + test('should have 10ms delay', () => { + expect(directive.delay).toBe(10); + }); + + test('should focus element after given delay', done => { + timer(0).subscribe(() => expect('input').not.toBeFocused()); + timer(11).subscribe(() => { + expect('input').toBeFocused(); + done(); + }); + }); +});