Skip to content

Commit

Permalink
test(ripple): refactor long-running unit test (#2155)
Browse files Browse the repository at this point in the history
Refactors a unit test that used to take 1.6s, due to it using a native `setTimeout`, by replacing the native timer with a flushable one.

Fixes #2097.
  • Loading branch information
crisbeto authored and jelbourn committed Dec 14, 2016
1 parent bac0388 commit b3e21b8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/lib/core/ripple/ripple.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestBed, ComponentFixture, async} from '@angular/core/testing';
import {TestBed, ComponentFixture, fakeAsync, tick} from '@angular/core/testing';
import {Component, ViewChild} from '@angular/core';
import {MdRipple, MdRippleModule} from './ripple';

Expand Down Expand Up @@ -132,14 +132,13 @@ describe('MdRipple', () => {
expect(rippleElement.querySelectorAll('.md-ripple-foreground').length).toBe(0);
});

it('removes foreground ripples after timeout', async(() => {
it('removes foreground ripples after timeout', fakeAsync(() => {
rippleElement.click();
expect(rippleElement.querySelectorAll('.md-ripple-foreground').length).toBe(1);

// Use a real timeout because the ripple's timeout runs outside of the angular zone.
setTimeout(() => {
expect(rippleElement.querySelectorAll('.md-ripple-foreground').length).toBe(0);
}, 1600);
tick(1600);

expect(rippleElement.querySelectorAll('.md-ripple-foreground').length).toBe(0);
}));

it('creates ripples when manually triggered', () => {
Expand Down

0 comments on commit b3e21b8

Please sign in to comment.