Skip to content

Commit e1481e4

Browse files
authored
test: attempt to resolve flaky tests (#33166)
Attempts to resolve some test flakiness after the switch to `fakeAsync`.
1 parent af49eee commit e1481e4

3 files changed

Lines changed: 30 additions & 29 deletions

File tree

src/cdk/drag-drop/directives/drop-list-shared.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,7 +2733,7 @@ export function defineCommonDropListTests(config: {
27332733
startDraggingViaMouse(fixture, item);
27342734
dispatchMouseEvent(document, 'mousemove', listRect.left + listRect.width / 2, 0);
27352735
fixture.detectChanges();
2736-
await wait(10);
2736+
await wait(100);
27372737

27382738
expect(viewportRuler.getViewportScrollPosition().top).toBe(initialScrollDistance);
27392739
expect(list.scrollTop).toBeLessThan(50);
@@ -2770,7 +2770,7 @@ export function defineCommonDropListTests(config: {
27702770
startDraggingViaMouse(fixture, item);
27712771
dispatchMouseEvent(document, 'mousemove', listRect.left + listRect.width / 2, 0);
27722772
fixture.detectChanges();
2773-
await wait(10);
2773+
await wait(100);
27742774

27752775
expect(viewportRuler.getViewportScrollPosition().top).toBeLessThan(initialScrollDistance);
27762776
expect(list.scrollTop).toBe(0);

src/material/sidenav/drawer.spec.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('MatDrawer', () => {
4545
expect(testComponent.openStartCount).toBe(0);
4646
expect(container.classList).not.toContain('mat-drawer-container-has-open');
4747

48-
await wait(20);
48+
await wait(100);
4949
expect(testComponent.openStartCount).toBe(1);
5050
fixture.detectChanges();
5151

@@ -72,7 +72,7 @@ describe('MatDrawer', () => {
7272
expect(testComponent.closeCount).toBe(0);
7373
expect(testComponent.closeStartCount).toBe(0);
7474

75-
await wait(20);
75+
await wait(100);
7676
expect(testComponent.closeStartCount).toBeGreaterThanOrEqual(1);
7777
fixture.detectChanges();
7878

@@ -181,7 +181,7 @@ describe('MatDrawer', () => {
181181

182182
drawer.componentInstance.open();
183183
fixture.detectChanges();
184-
await wait(20);
184+
await wait(100);
185185

186186
expect(testComponent.openCount).withContext('Expected one open event.').toBe(1);
187187
expect(testComponent.openStartCount).withContext('Expected one open start event.').toBe(1);
@@ -190,7 +190,7 @@ describe('MatDrawer', () => {
190190

191191
const event = dispatchKeyboardEvent(drawer.nativeElement, 'keydown', ESCAPE);
192192
fixture.detectChanges();
193-
await wait(20);
193+
await wait(100);
194194

195195
expect(testComponent.closeCount).withContext('Expected one close event.').toBe(1);
196196
expect(testComponent.closeStartCount).withContext('Expected one close start event.').toBe(1);
@@ -228,7 +228,7 @@ describe('MatDrawer', () => {
228228
const fixture = TestBed.createComponent(DrawerSetToOpenedTrue);
229229

230230
fixture.detectChanges();
231-
await wait(20);
231+
await wait(100);
232232

233233
expect(fixture.componentInstance.openCallback).toHaveBeenCalledTimes(1);
234234
});
@@ -280,7 +280,7 @@ describe('MatDrawer', () => {
280280
openButton.focus();
281281
drawer.open();
282282
fixture.detectChanges();
283-
await wait(20);
283+
await wait(100);
284284
fixture.detectChanges();
285285

286286
const backdrop = fixture.nativeElement.querySelector('.mat-drawer-backdrop');
@@ -294,7 +294,7 @@ describe('MatDrawer', () => {
294294

295295
backdrop.click();
296296
fixture.detectChanges();
297-
await wait(20);
297+
await wait(100);
298298

299299
expect(document.activeElement)
300300
.withContext('Expected focus to be restored to the open button on close.')
@@ -313,13 +313,13 @@ describe('MatDrawer', () => {
313313
openButton.focus();
314314
drawer.open();
315315
fixture.detectChanges();
316-
await wait(20);
316+
await wait(100);
317317
fixture.detectChanges();
318318
drawerButton.focus();
319319

320320
drawer.close();
321321
fixture.detectChanges();
322-
await wait(20);
322+
await wait(100);
323323

324324
expect(document.activeElement)
325325
.withContext('Expected focus to be restored to the open button on close.')
@@ -337,13 +337,13 @@ describe('MatDrawer', () => {
337337
svg.focus();
338338
drawer.open();
339339
fixture.detectChanges();
340-
await wait(20);
340+
await wait(100);
341341
fixture.detectChanges();
342342
drawerButton.focus();
343343

344344
drawer.close();
345345
fixture.detectChanges();
346-
await wait(20);
346+
await wait(100);
347347

348348
expect(document.activeElement)
349349
.withContext('Expected focus to be restored to the SVG element on close.')
@@ -496,7 +496,7 @@ describe('MatDrawer', () => {
496496

497497
drawer.open();
498498
fixture.detectChanges();
499-
await wait(20);
499+
await wait(100);
500500

501501
expect(fixture.componentInstance.isOpen).toBe(true);
502502
});
@@ -546,7 +546,7 @@ describe('MatDrawer', () => {
546546

547547
drawer.open();
548548
fixture.detectChanges();
549-
await wait(20);
549+
await wait(100);
550550
fixture.detectChanges();
551551

552552
expect(document.activeElement).toBe(firstFocusableElement);
@@ -560,7 +560,7 @@ describe('MatDrawer', () => {
560560

561561
drawer.open();
562562
fixture.detectChanges();
563-
await wait(20);
563+
await wait(100);
564564
fixture.detectChanges();
565565

566566
expect(document.activeElement).toBe(firstFocusableElement);
@@ -575,7 +575,7 @@ describe('MatDrawer', () => {
575575

576576
drawer.open();
577577
fixture.detectChanges();
578-
await wait(20);
578+
await wait(100);
579579
fixture.detectChanges();
580580

581581
expect(document.activeElement).toBe(firstFocusableElement);
@@ -618,7 +618,7 @@ describe('MatDrawer', () => {
618618

619619
drawer.open();
620620
fixture.detectChanges();
621-
await wait(20);
621+
await wait(100);
622622
fixture.detectChanges();
623623

624624
expect(document.activeElement).toBe(firstFocusableElement);
@@ -633,7 +633,7 @@ describe('MatDrawer', () => {
633633

634634
drawerEl.componentInstance.open();
635635
nonFocusableFixture.detectChanges();
636-
await wait(20);
636+
await wait(100);
637637
nonFocusableFixture.detectChanges();
638638

639639
expect(document.activeElement).toBe(drawerEl.nativeElement);
@@ -904,7 +904,7 @@ describe('MatDrawerContainer', () => {
904904

905905
fixture.componentInstance.drawer.open();
906906
fixture.detectChanges();
907-
await wait(20);
907+
await wait(100);
908908
fixture.detectChanges();
909909

910910
expect(parseInt(contentElement.style.marginLeft)).toBeGreaterThan(0);
@@ -916,7 +916,7 @@ describe('MatDrawerContainer', () => {
916916
fixture.detectChanges();
917917
fixture.componentInstance.drawer.open();
918918
fixture.detectChanges();
919-
await wait(20);
919+
await wait(100);
920920
fixture.detectChanges();
921921

922922
const contentElement = fixture.debugElement.nativeElement.querySelector('.mat-drawer-content');
@@ -938,7 +938,7 @@ describe('MatDrawerContainer', () => {
938938
fixture.detectChanges();
939939
fixture.componentInstance.drawer.open();
940940
fixture.detectChanges();
941-
await wait(20);
941+
await wait(100);
942942
fixture.detectChanges();
943943

944944
const contentElement = fixture.debugElement.nativeElement.querySelector('.mat-drawer-content');
@@ -959,7 +959,7 @@ describe('MatDrawerContainer', () => {
959959
fixture.detectChanges();
960960
fixture.componentInstance.drawer.open();
961961
fixture.detectChanges();
962-
await wait(20);
962+
await wait(100);
963963
fixture.detectChanges();
964964

965965
const contentElement = fixture.debugElement.nativeElement.querySelector('.mat-drawer-content');
@@ -998,7 +998,7 @@ describe('MatDrawerContainer', () => {
998998
fixture.nativeElement.querySelector('.mat-drawer').style.width = 'auto';
999999
fixture.componentInstance.drawer.open();
10001000
fixture.detectChanges();
1001-
await wait(20);
1001+
await wait(100);
10021002
fixture.detectChanges();
10031003

10041004
const contentEl = fixture.debugElement.nativeElement.querySelector('.mat-drawer-content');
@@ -1009,7 +1009,7 @@ describe('MatDrawerContainer', () => {
10091009
fixture.componentInstance.fillerWidth = 200;
10101010
fixture.changeDetectorRef.markForCheck();
10111011
fixture.detectChanges();
1012-
await wait(20);
1012+
await wait(100);
10131013
fixture.detectChanges();
10141014

10151015
expect(parseInt(contentEl.style.marginLeft)).toBeGreaterThan(initialMargin);
@@ -1027,15 +1027,15 @@ describe('MatDrawerContainer', () => {
10271027
// Open the drawer and resolve the open animation.
10281028
fixture.componentInstance.drawer.open();
10291029
fixture.detectChanges();
1030-
await wait(20);
1030+
await wait(100);
10311031
fixture.detectChanges();
10321032

10331033
expect(content.style.marginLeft).not.toBe('', 'Margin should be present when drawer is open');
10341034

10351035
// Close the drawer and resolve the close animation.
10361036
fixture.componentInstance.drawer.close();
10371037
fixture.detectChanges();
1038-
await wait(20);
1038+
await wait(100);
10391039
fixture.detectChanges();
10401040

10411041
expect(content.style.marginLeft)

src/material/tooltip/tooltip.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,12 +1277,13 @@ describe('MatTooltip', () => {
12771277

12781278
dispatchFakeEvent(button, 'touchstart');
12791279
fixture.detectChanges();
1280-
await wait(250); // Halfway through the dela.
1280+
await wait(250); // Halfway through the delay.
12811281

12821282
assertTooltipInstance(fixture.componentInstance.tooltip, false);
12831283

1284-
await wait(500); // Finish the dela.
1284+
await wait(600); // Finish the delay.
12851285
fixture.detectChanges();
1286+
await fixture.whenStable();
12861287
finishCurrentTooltipAnimation(overlayContainerElement, true); // Finish the animation.
12871288

12881289
assertTooltipInstance(fixture.componentInstance.tooltip, true);

0 commit comments

Comments
 (0)