Skip to content

Commit 6be9b4c

Browse files
committed
test(material/sort): switch tests away from fakeAsync (angular#33716)
Reworks the `sort` tests not to depend on `fakeAsync`. (cherry picked from commit ef620d8)
1 parent 98842bf commit 6be9b4c

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

src/material/sort/sort.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {CollectionViewer, DataSource} from '@angular/cdk/collections';
22
import {CdkTableModule} from '@angular/cdk/table';
33
import {dispatchMouseEvent, wrappedErrorMessage} from '@angular/cdk/testing/private';
44
import {Component, ElementRef, ViewChild, inject, ChangeDetectionStrategy} from '@angular/core';
5-
import {ComponentFixture, TestBed, fakeAsync, tick, waitForAsync} from '@angular/core/testing';
5+
import {ComponentFixture, TestBed} from '@angular/core/testing';
66
import {MatTableModule} from '../table';
77
import {By} from '@angular/platform-browser';
88
import {Observable} from 'rxjs';
@@ -43,13 +43,13 @@ describe('MatSort', () => {
4343
expect(sortables.size).toBe(0);
4444
});
4545

46-
it('should mark itself as initialized', fakeAsync(() => {
46+
it('should mark itself as initialized', async () => {
4747
let isMarkedInitialized = false;
4848
component.matSort.initialized.subscribe(() => (isMarkedInitialized = true));
4949

50-
tick();
50+
await fixture.whenStable();
5151
expect(isMarkedInitialized).toBeTruthy();
52-
}));
52+
});
5353

5454
it('should use the column definition if used within a cdk table', () => {
5555
const cdkTableMatSortAppFixture = TestBed.createComponent(CdkTableMatSortApp);
@@ -209,32 +209,32 @@ describe('MatSort', () => {
209209
expect(sortHeaderElement.getAttribute('aria-sort')).toBe('none');
210210
});
211211

212-
it('should not render the arrow if sorting is disabled for that column', fakeAsync(() => {
212+
it('should not render the arrow if sorting is disabled for that column', async () => {
213213
const sortHeaderElement = fixture.nativeElement.querySelector('#defaultA');
214214

215215
// Switch sorting to a different column before asserting.
216216
component.sort('defaultB');
217217
fixture.componentInstance.disabledColumnSort = true;
218218
fixture.changeDetectorRef.markForCheck();
219219
fixture.detectChanges();
220-
tick();
220+
await fixture.whenStable();
221221
fixture.detectChanges();
222222

223223
expect(sortHeaderElement.querySelector('.mat-sort-header-arrow')).toBeFalsy();
224-
}));
224+
});
225225

226-
it('should render the arrow if a disabled column is being sorted by', fakeAsync(() => {
226+
it('should render the arrow if a disabled column is being sorted by', async () => {
227227
const sortHeaderElement = fixture.nativeElement.querySelector('#defaultA');
228228

229229
component.sort('defaultA');
230230
fixture.componentInstance.disabledColumnSort = true;
231231
fixture.changeDetectorRef.markForCheck();
232232
fixture.detectChanges();
233-
tick();
233+
await fixture.whenStable();
234234
fixture.detectChanges();
235235

236236
expect(sortHeaderElement.querySelector('.mat-sort-header-arrow')).toBeTruthy();
237-
}));
237+
});
238238

239239
it('should have a focus indicator', () => {
240240
const headerNativeElement = fixture.debugElement.query(
@@ -336,7 +336,7 @@ describe('MatSort', () => {
336336
let fixture: ComponentFixture<MatSortWithoutExplicitInputs>;
337337
let component: MatSortWithoutExplicitInputs;
338338

339-
beforeEach(waitForAsync(() => {
339+
beforeEach(() => {
340340
TestBed.configureTestingModule({
341341
providers: [
342342
{
@@ -347,7 +347,7 @@ describe('MatSort', () => {
347347
},
348348
],
349349
});
350-
}));
350+
});
351351

352352
beforeEach(() => {
353353
fixture = TestBed.createComponent(MatSortWithoutExplicitInputs);
@@ -368,7 +368,7 @@ describe('MatSort', () => {
368368
describe('with default arrowPosition', () => {
369369
let fixture: ComponentFixture<MatSortWithoutInputs>;
370370

371-
beforeEach(waitForAsync(() => {
371+
beforeEach(() => {
372372
TestBed.configureTestingModule({
373373
providers: [
374374
{
@@ -380,7 +380,7 @@ describe('MatSort', () => {
380380
},
381381
],
382382
});
383-
}));
383+
});
384384

385385
beforeEach(() => {
386386
fixture = TestBed.createComponent(MatSortWithoutInputs);

0 commit comments

Comments
 (0)