Skip to content

Commit fccc2ef

Browse files
authored
refactor(cdk/scrolling): switch tests away from fakeAsync (#33150)
Reworks the CDK scrolling tests not to depend on `fakeAsync` anymore.
1 parent 13c92a3 commit fccc2ef

4 files changed

Lines changed: 357 additions & 363 deletions

File tree

src/cdk/scrolling/scroll-dispatcher.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TestBed, fakeAsync, ComponentFixture, tick} from '@angular/core/testing';
1+
import {TestBed, ComponentFixture} from '@angular/core/testing';
22
import {Component, ViewChild, ElementRef, ChangeDetectionStrategy} from '@angular/core';
33
import {CdkScrollable, ScrollDispatcher, ScrollingModule} from './public-api';
44
import {dispatchFakeEvent} from '../testing/private';
@@ -31,7 +31,7 @@ describe('ScrollDispatcher', () => {
3131
expect(scroll.scrollContainers.has(componentScrollable)).toBe(false);
3232
});
3333

34-
it('should notify through the directive and service that a scroll event occurred', fakeAsync(() => {
34+
it('should notify through the directive and service that a scroll event occurred', async () => {
3535
// Listen for notifications from scroll directive
3636
const scrollable = fixture.componentInstance.scrollable;
3737
const directiveSpy = jasmine.createSpy('directive scroll callback');
@@ -55,9 +55,9 @@ describe('ScrollDispatcher', () => {
5555
expect(serviceSpy).not.toHaveBeenCalled();
5656

5757
// After the throttle time, the notification should be sent.
58-
tick(throttleTime);
58+
await new Promise(resolve => setTimeout(resolve, throttleTime + 10));
5959
expect(serviceSpy).toHaveBeenCalled();
60-
}));
60+
});
6161

6262
it('should be able to unsubscribe from the global scrollable', () => {
6363
const spy = jasmine.createSpy('global scroll callback');

src/cdk/scrolling/viewport-ruler.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TestBed, fakeAsync, tick} from '@angular/core/testing';
1+
import {TestBed} from '@angular/core/testing';
22
import {dispatchFakeEvent} from '../testing/private';
33
import {ViewportRuler} from './viewport-ruler';
44

@@ -109,17 +109,17 @@ describe('ViewportRuler', () => {
109109
subscription.unsubscribe();
110110
});
111111

112-
it('should be able to throttle the callback', fakeAsync(() => {
112+
it('should be able to throttle the callback', async () => {
113113
const spy = jasmine.createSpy('viewport changed spy');
114-
const subscription = viewportRuler.change(1337).subscribe(spy);
114+
const subscription = viewportRuler.change(10).subscribe(spy);
115115

116116
dispatchFakeEvent(window, 'resize');
117117
expect(spy).not.toHaveBeenCalled();
118118

119-
tick(1337);
119+
await new Promise(resolve => setTimeout(resolve, 20));
120120

121121
expect(spy).toHaveBeenCalledTimes(1);
122122
subscription.unsubscribe();
123-
}));
123+
});
124124
});
125125
});

0 commit comments

Comments
 (0)