Skip to content

chore: fix tests leaking overlay containers #9076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cdk/overlay/overlay-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('OverlayContainer', () => {
overlayRef.attach(fixture.componentInstance.templatePortal);
fixture.detectChanges();

expect(document.querySelectorAll('.cdk-overlay-container'))
expect(document.querySelector('.cdk-overlay-container'))
.not.toBeNull('Expected the overlay container to be in the DOM after opening an overlay');

// Manually call `ngOnDestroy` because there is no way to force Angular to destroy an
Expand Down
12 changes: 7 additions & 5 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ describe('MatAutocomplete', () => {
return TestBed.createComponent(component);
}

afterEach(() => {
if (overlayContainer) {
overlayContainer.ngOnDestroy();
}
});
afterEach(inject([OverlayContainer], (currentOverlayContainer: OverlayContainer) => {
// Since we're resetting the testing module in some of the tests,
// we can potentially have multiple overlay containers.
currentOverlayContainer.ngOnDestroy();
overlayContainer.ngOnDestroy();
}));

describe('panel toggling', () => {
let fixture: ComponentFixture<SimpleAutocomplete>;
Expand Down Expand Up @@ -598,6 +599,7 @@ describe('MatAutocomplete', () => {
});

it('should disable the input when used with a value accessor and without `matInput`', () => {
overlayContainer.ngOnDestroy();
fixture.destroy();
TestBed.resetTestingModule();

Expand Down
7 changes: 5 additions & 2 deletions src/lib/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ describe('MatMenu', () => {
})();
}));

afterEach(() => {
afterEach(inject([OverlayContainer], (currentOverlayContainer: OverlayContainer) => {
// Since we're resetting the testing module in some of the tests,
// we can potentially have multiple overlay containers.
currentOverlayContainer.ngOnDestroy();
overlayContainer.ngOnDestroy();
});
}));

it('should open the menu as an idempotent operation', () => {
const fixture = TestBed.createComponent(SimpleMenu);
Expand Down
7 changes: 5 additions & 2 deletions src/lib/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ describe('MatTooltip', () => {
})();
}));

afterEach(() => {
afterEach(inject([OverlayContainer], (currentOverlayContainer: OverlayContainer) => {
// Since we're resetting the testing module in some of the tests,
// we can potentially have multiple overlay containers.
currentOverlayContainer.ngOnDestroy();
overlayContainer.ngOnDestroy();
});
}));

describe('basic usage', () => {
let fixture: ComponentFixture<BasicTooltipDemo>;
Expand Down