diff --git a/src/Squidex/app-config/karma.conf.js b/src/Squidex/app-config/karma.conf.js index e13359e66..852cce536 100644 --- a/src/Squidex/app-config/karma.conf.js +++ b/src/Squidex/app-config/karma.conf.js @@ -33,11 +33,17 @@ module.exports = function (config) { noInfo: true }, + /* + * leave Jasmine Spec Runner output visible in browser + */ + client: { + clearContext: false + }, /* - * Use a mocha style console reporter, html reporter and the code coverage reporter + * Use a mocha style console reporter and html reporter. */ - reporters: ['mocha'], + reporters: ['kjhtml', 'mocha'], /** diff --git a/src/Squidex/app/framework/angular/focus-on-init.directive.spec.ts b/src/Squidex/app/framework/angular/focus-on-init.directive.spec.ts index bce92105c..6e0724110 100644 --- a/src/Squidex/app/framework/angular/focus-on-init.directive.spec.ts +++ b/src/Squidex/app/framework/angular/focus-on-init.directive.spec.ts @@ -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]); }); }); diff --git a/src/Squidex/app/framework/angular/focus-on-init.directive.ts b/src/Squidex/app/framework/angular/focus-on-init.directive.ts index 4832bb39e..6f489d9ef 100644 --- a/src/Squidex/app/framework/angular/focus-on-init.directive.ts +++ b/src/Squidex/app/framework/angular/focus-on-init.directive.ts @@ -5,12 +5,12 @@ * Copyright (c) Sebastian Stehle. All rights reserved */ -import { Directive, ElementRef, Input, OnInit, Renderer } from '@angular/core'; +import { AfterViewInit, Directive, ElementRef, Input, Renderer } from '@angular/core'; @Directive({ selector: '[sqxFocusOnInit]' }) -export class FocusOnInitDirective implements OnInit { +export class FocusOnInitDirective implements AfterViewInit { @Input() public select: boolean; @@ -20,13 +20,11 @@ export class FocusOnInitDirective implements OnInit { ) { } - public ngOnInit() { - setTimeout(() => { - this.renderer.invokeElementMethod(this.element.nativeElement, 'focus', []); + public ngAfterViewInit() { + this.renderer.invokeElementMethod(this.element.nativeElement, 'focus', []); - if (this.select) { - this.renderer.invokeElementMethod(this.element.nativeElement, 'select', []); - } - }); + if (this.select) { + this.renderer.invokeElementMethod(this.element.nativeElement, 'select', []); + } } } \ No newline at end of file diff --git a/src/Squidex/package.json b/src/Squidex/package.json index 5a7b9378a..9073bd9b8 100644 --- a/src/Squidex/package.json +++ b/src/Squidex/package.json @@ -71,6 +71,7 @@ "karma-coverage": "1.1.1", "karma-htmlfile-reporter": "0.3.5", "karma-jasmine": "1.1.0", + "karma-jasmine-html-reporter": "^0.2.2", "karma-mocha-reporter": "2.2.3", "karma-phantomjs-launcher": "1.0.4", "karma-sourcemap-loader": "0.3.7", @@ -93,4 +94,4 @@ "webpack-dev-server": "2.5.1", "webpack-merge": "4.1.0" } -} \ No newline at end of file +}