diff --git a/src/cdk/overlay/overlay-container.spec.ts b/src/cdk/overlay/overlay-container.spec.ts index ee635f22f033..312ddfb96a5b 100644 --- a/src/cdk/overlay/overlay-container.spec.ts +++ b/src/cdk/overlay/overlay-container.spec.ts @@ -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 diff --git a/src/lib/autocomplete/autocomplete.spec.ts b/src/lib/autocomplete/autocomplete.spec.ts index fbf79bda30eb..3425f263732a 100644 --- a/src/lib/autocomplete/autocomplete.spec.ts +++ b/src/lib/autocomplete/autocomplete.spec.ts @@ -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; @@ -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(); diff --git a/src/lib/menu/menu.spec.ts b/src/lib/menu/menu.spec.ts index 13443427e397..8fdaffa64048 100644 --- a/src/lib/menu/menu.spec.ts +++ b/src/lib/menu/menu.spec.ts @@ -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); diff --git a/src/lib/tooltip/tooltip.spec.ts b/src/lib/tooltip/tooltip.spec.ts index 5291b89b5948..f892f6e0f050 100644 --- a/src/lib/tooltip/tooltip.spec.ts +++ b/src/lib/tooltip/tooltip.spec.ts @@ -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;