Skip to content

Commit 4fbe62e

Browse files
author
Matt Lewis
committed
test: fix tests in watch mode
1 parent eb0bff0 commit 4fbe62e

4 files changed

+64
-53
lines changed

test/calendarDayView.component.spec.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {
22
inject,
33
ComponentFixture,
44
TestBed,
5+
fakeAsync,
6+
flush,
57
async
68
} from '@angular/core/testing';
79
import * as moment from 'moment';
@@ -373,7 +375,7 @@ describe('CalendarDayViewComponent component', () => {
373375
});
374376
});
375377

376-
it('should show a tooltip on mouseover of the event', () => {
378+
it('should show a tooltip on mouseover of the event', fakeAsync(() => {
377379

378380
const fixture: ComponentFixture<CalendarDayViewComponent> = TestBed.createComponent(CalendarDayViewComponent);
379381
eventTitle.dayTooltip = (event: CalendarEvent) => {
@@ -394,20 +396,19 @@ describe('CalendarDayViewComponent component', () => {
394396
const event: HTMLElement = fixture.nativeElement.querySelector('.cal-event');
395397
triggerDomEvent('mouseenter', event);
396398
fixture.detectChanges();
397-
setTimeout(() => {
398-
const tooltip: HTMLElement = document.body.querySelector('.cal-tooltip') as HTMLElement;
399-
expect(tooltip.querySelector('.cal-tooltip-inner').innerHTML).to.equal('title: foo <b>bar</b>');
400-
expect(tooltip.classList.contains('cal-tooltip-top')).to.equal(true);
401-
expect(!!tooltip.style.top).to.equal(true);
402-
expect(!!tooltip.style.left).to.equal(true);
403-
triggerDomEvent('mouseleave', event);
404-
fixture.detectChanges();
405-
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
406-
});
399+
flush();
400+
const tooltip: HTMLElement = document.body.querySelector('.cal-tooltip') as HTMLElement;
401+
expect(tooltip.querySelector('.cal-tooltip-inner').innerHTML).to.equal('title: foo <b>bar</b>');
402+
expect(tooltip.classList.contains('cal-tooltip-top')).to.equal(true);
403+
expect(!!tooltip.style.top).to.equal(true);
404+
expect(!!tooltip.style.left).to.equal(true);
405+
triggerDomEvent('mouseleave', event);
406+
fixture.detectChanges();
407+
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
407408

408-
});
409+
}));
409410

410-
it('should disable the tooltip', () => {
411+
it('should disable the tooltip', fakeAsync(() => {
411412

412413
const fixture: ComponentFixture<CalendarDayViewComponent> = TestBed.createComponent(CalendarDayViewComponent);
413414
eventTitle.dayTooltip = () => '';
@@ -426,11 +427,10 @@ describe('CalendarDayViewComponent component', () => {
426427
const event: HTMLElement = fixture.nativeElement.querySelector('.cal-event');
427428
triggerDomEvent('mouseenter', event);
428429
fixture.detectChanges();
429-
setTimeout(() => {
430-
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
431-
});
430+
flush();
431+
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
432432

433-
});
433+
}));
434434

435435
it('should allow events to be dragged and dropped', () => {
436436
const fixture: ComponentFixture<CalendarDayViewComponent> = TestBed.createComponent(CalendarDayViewComponent);

test/calendarMonthView.component.spec.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
22
inject,
33
ComponentFixture,
4-
TestBed
4+
TestBed,
5+
fakeAsync,
6+
flush
57
} from '@angular/core/testing';
68
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
79
import * as moment from 'moment';
@@ -295,7 +297,7 @@ describe('calendarMonthView component', () => {
295297
fixture.destroy();
296298
});
297299

298-
it('should show a tooltip on mouseover of the event', () => {
300+
it('should show a tooltip on mouseover of the event', fakeAsync(() => {
299301

300302
const fixture: ComponentFixture<CalendarMonthViewComponent> = TestBed.createComponent(CalendarMonthViewComponent);
301303
eventTitle.monthTooltip = (event: CalendarEvent) => {
@@ -318,20 +320,19 @@ describe('calendarMonthView component', () => {
318320
);
319321
triggerDomEvent('mouseenter', event);
320322
fixture.detectChanges();
321-
setTimeout(() => {
322-
const tooltip: HTMLElement = document.body.querySelector('.cal-tooltip') as HTMLElement;
323-
expect(tooltip.querySelector('.cal-tooltip-inner').innerHTML).to.equal('title: foo <b>bar</b>');
324-
expect(tooltip.classList.contains('cal-tooltip-top')).to.equal(true);
325-
expect(!!tooltip.style.top).to.equal(true);
326-
expect(!!tooltip.style.left).to.equal(true);
327-
triggerDomEvent('mouseleave', event);
328-
fixture.detectChanges();
329-
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
330-
});
323+
flush();
324+
const tooltip: HTMLElement = document.body.querySelector('.cal-tooltip') as HTMLElement;
325+
expect(tooltip.querySelector('.cal-tooltip-inner').innerHTML).to.equal('title: foo <b>bar</b>');
326+
expect(tooltip.classList.contains('cal-tooltip-top')).to.equal(true);
327+
expect(!!tooltip.style.top).to.equal(true);
328+
expect(!!tooltip.style.left).to.equal(true);
329+
triggerDomEvent('mouseleave', event);
330+
fixture.detectChanges();
331+
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
331332

332-
});
333+
}));
333334

334-
it('should disable the tooltip', () => {
335+
it('should disable the tooltip', fakeAsync(() => {
335336

336337
const fixture: ComponentFixture<CalendarMonthViewComponent> = TestBed.createComponent(CalendarMonthViewComponent);
337338
eventTitle.monthTooltip = () => '';
@@ -352,11 +353,10 @@ describe('calendarMonthView component', () => {
352353
);
353354
triggerDomEvent('mouseenter', event);
354355
fixture.detectChanges();
355-
setTimeout(() => {
356-
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
357-
});
356+
flush();
357+
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
358358

359-
});
359+
}));
360360

361361
it('should allow the start of the week to be changed', () => {
362362
const fixture: ComponentFixture<CalendarMonthViewComponent> = TestBed.createComponent(CalendarMonthViewComponent);

test/calendarWeekView.component.spec.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
22
inject,
33
ComponentFixture,
4-
TestBed
4+
TestBed,
5+
fakeAsync,
6+
flush
57
} from '@angular/core/testing';
68
import * as moment from 'moment';
79
import { expect } from 'chai';
@@ -192,7 +194,7 @@ describe('calendarWeekView component', () => {
192194

193195
});
194196

195-
it('should show a tooltip on mouseover of the event', () => {
197+
it('should show a tooltip on mouseover of the event', fakeAsync(() => {
196198

197199
const fixture: ComponentFixture<CalendarWeekViewComponent> = TestBed.createComponent(CalendarWeekViewComponent);
198200
eventTitle.weekTooltip = (event: CalendarEvent) => {
@@ -213,20 +215,19 @@ describe('calendarWeekView component', () => {
213215
const event: HTMLElement = fixture.nativeElement.querySelector('.cal-event');
214216
triggerDomEvent('mouseenter', event);
215217
fixture.detectChanges();
216-
setTimeout(() => {
217-
const tooltip: HTMLElement = document.body.querySelector('.cal-tooltip') as HTMLElement;
218-
expect(tooltip.querySelector('.cal-tooltip-inner').innerHTML).to.equal('title: foo <b>bar</b>');
219-
expect(tooltip.classList.contains('cal-tooltip-bottom')).to.equal(true);
220-
expect(!!tooltip.style.top).to.equal(true);
221-
expect(!!tooltip.style.left).to.equal(true);
222-
triggerDomEvent('mouseleave', event);
223-
fixture.detectChanges();
224-
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
225-
});
218+
flush();
219+
const tooltip: HTMLElement = document.body.querySelector('.cal-tooltip') as HTMLElement;
220+
expect(tooltip.querySelector('.cal-tooltip-inner').innerHTML).to.equal('title: foo <b>bar</b>');
221+
expect(tooltip.classList.contains('cal-tooltip-bottom')).to.equal(true);
222+
expect(!!tooltip.style.top).to.equal(true);
223+
expect(!!tooltip.style.left).to.equal(true);
224+
triggerDomEvent('mouseleave', event);
225+
fixture.detectChanges();
226+
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
226227

227-
});
228+
}));
228229

229-
it('should disable the tooltip', () => {
230+
it('should disable the tooltip', fakeAsync(() => {
230231

231232
const fixture: ComponentFixture<CalendarWeekViewComponent> = TestBed.createComponent(CalendarWeekViewComponent);
232233
eventTitle.weekTooltip = () => '';
@@ -245,11 +246,10 @@ describe('calendarWeekView component', () => {
245246
const event: HTMLElement = fixture.nativeElement.querySelector('.cal-event');
246247
triggerDomEvent('mouseenter', event);
247248
fixture.detectChanges();
248-
setTimeout(() => {
249-
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
250-
});
249+
flush();
250+
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
251251

252-
});
252+
}));
253253

254254
it('should allow the start of the week to be changed', () => {
255255
const fixture: ComponentFixture<CalendarWeekViewComponent> = TestBed.createComponent(CalendarWeekViewComponent);

test/entry.ts

+11
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,24 @@ import 'intl/locale-data/jsonp/de';
1919
import 'moment/locale/de';
2020
import 'moment/locale/en-ca';
2121
import { use } from 'chai';
22+
import * as sinon from 'sinon';
2223
import * as sinonChai from 'sinon-chai';
2324
import { TestBed } from '@angular/core/testing';
2425
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
2526

2627
use(sinonChai);
2728
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
2829

30+
let rafStub: sinon.SinonStub;
31+
beforeEach(() => {
32+
// TODO - delete this once zone.js v0.8.13 lands
33+
rafStub = sinon.stub(window, 'requestAnimationFrame').callsArg(0);
34+
});
35+
36+
afterEach(() => {
37+
rafStub.restore();
38+
});
39+
2940
declare const require: any;
3041
const testsContext: any = require.context('./', true, /\.spec/);
3142
testsContext.keys().forEach(testsContext);

0 commit comments

Comments
 (0)