|
|
|
@ -10,15 +10,7 @@ import { ElementRef, Renderer } from '@angular/core'; |
|
|
|
import { FocusOnInitDirective } from './focus-on-init.directive'; |
|
|
|
|
|
|
|
describe('FocusOnInitDirective', () => { |
|
|
|
let originalTimeout = 0; |
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; |
|
|
|
|
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 800; |
|
|
|
}); |
|
|
|
|
|
|
|
it('should call focus on element when init', (done: any) => { |
|
|
|
it('should call focus on element when init', () => { |
|
|
|
const calledMethods: string[] = []; |
|
|
|
const calledElements: any[] = []; |
|
|
|
|
|
|
|
@ -35,19 +27,9 @@ describe('FocusOnInitDirective', () => { |
|
|
|
|
|
|
|
const directive = new FocusOnInitDirective(element, renderer as Renderer); |
|
|
|
directive.select = true; |
|
|
|
directive.ngOnInit(); |
|
|
|
|
|
|
|
expect(calledMethods).toEqual([]); |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
expect(calledMethods).toEqual(['focus', 'select']); |
|
|
|
expect(calledElements).toEqual([element.nativeElement, element.nativeElement]); |
|
|
|
|
|
|
|
done(); |
|
|
|
}, 400); |
|
|
|
}); |
|
|
|
directive.ngAfterViewInit(); |
|
|
|
|
|
|
|
afterEach(() => { |
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; |
|
|
|
expect(calledMethods).toEqual(['focus', 'select']); |
|
|
|
expect(calledElements).toEqual([element.nativeElement, element.nativeElement]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|