From a22d7a00e951f91bf39a40613aa1123cb501225c Mon Sep 17 00:00:00 2001 From: thediaval Date: Fri, 8 Nov 2019 11:42:39 +0300 Subject: [PATCH] test(core): add autofocus directive test --- .../src/lib/tests/autofocus.directive.spec.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 npm/ng-packs/packages/core/src/lib/tests/autofocus.directive.spec.ts 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(); + }); + }); +});