Skip to content

Commit 253bff6

Browse files
crisbetoandrewseguin
authored andcommitted
build: fix IE and Edge test flakes (#8909)
* Fixes the `OverlayKeyboardDispatcher` tests leaking `.cdk-overlay-container` instances which can throw off any subsequent tests. This seems to be what is causing the current test flakes in master that happen if the tests are run in a minimized browser window. * Gets rid of the explicit cleanup of overlay containers in the overlay container tests. This can cause tests to be even flakier if there are any leaks, in addition to being unnecessary because there shouldn't be any containers to begin with.
1 parent b6c462f commit 253bff6

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/cdk/overlay/keyboard/overlay-keyboard-dispatcher.spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import {TestBed, inject} from '@angular/core/testing';
22
import {dispatchKeyboardEvent} from '@angular/cdk/testing';
33
import {ESCAPE} from '@angular/cdk/keycodes';
44
import {Component, NgModule} from '@angular/core';
5-
import {Overlay} from '../overlay';
6-
import {OverlayModule} from '../index';
5+
import {OverlayModule, OverlayContainer, Overlay} from '../index';
76
import {OverlayKeyboardDispatcher} from './overlay-keyboard-dispatcher';
87
import {ComponentPortal} from '@angular/cdk/portal';
98

@@ -16,12 +15,15 @@ describe('OverlayKeyboardDispatcher', () => {
1615
TestBed.configureTestingModule({
1716
imports: [OverlayModule, TestComponentModule],
1817
});
18+
19+
inject([OverlayKeyboardDispatcher, Overlay], (kbd: OverlayKeyboardDispatcher, o: Overlay) => {
20+
keyboardDispatcher = kbd;
21+
overlay = o;
22+
})();
1923
});
2024

21-
beforeEach(inject([OverlayKeyboardDispatcher, Overlay],
22-
(kbd: OverlayKeyboardDispatcher, o: Overlay) => {
23-
keyboardDispatcher = kbd;
24-
overlay = o;
25+
afterEach(inject([OverlayContainer], (overlayContainer: OverlayContainer) => {
26+
overlayContainer.ngOnDestroy();
2527
}));
2628

2729
it('should track overlays in order as they are attached and detached', () => {

src/cdk/overlay/overlay-container.spec.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ describe('OverlayContainer', () => {
77
let overlay: Overlay;
88
let overlayContainer: OverlayContainer;
99

10-
beforeAll(() => {
11-
// Remove any stale overlay containers from previous tests that didn't clean up correctly.
12-
const staleContainers = document.querySelectorAll('.cdk-overlay-container');
13-
for (let i = staleContainers.length - 1; i >= 0; i--) {
14-
staleContainers[i].parentNode!.removeChild(staleContainers[i]);
15-
}
16-
});
17-
1810
beforeEach(async(() => {
1911
TestBed.configureTestingModule({
2012
imports: [OverlayTestModule]

0 commit comments

Comments
 (0)