Skip to content

Commit b3e21b8

Browse files
crisbetojelbourn
authored andcommitted
test(ripple): refactor long-running unit test (#2155)
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.
1 parent bac0388 commit b3e21b8

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/lib/core/ripple/ripple.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TestBed, ComponentFixture, async} from '@angular/core/testing';
1+
import {TestBed, ComponentFixture, fakeAsync, tick} from '@angular/core/testing';
22
import {Component, ViewChild} from '@angular/core';
33
import {MdRipple, MdRippleModule} from './ripple';
44

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

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

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

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

0 commit comments

Comments
 (0)