Skip to content

test(multiple): clean up manual ngOnDestroy calls #23423

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 1 commit into from
Aug 23, 2021
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
4 changes: 0 additions & 4 deletions src/cdk-experimental/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('Dialog', () => {
let testViewContainerRef: ViewContainerRef;
let viewContainerFixture: ComponentFixture<ComponentWithChildViewContainer>;
let mockLocation: SpyLocation;
let overlayContainer: OverlayContainer;

beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
Expand All @@ -59,7 +58,6 @@ describe('Dialog', () => {
(d: Dialog, l: Location, o: OverlayContainer) => {
dialog = d;
mockLocation = l as SpyLocation;
overlayContainer = o;
overlayContainerElement = o.getContainerElement();
}));

Expand All @@ -70,8 +68,6 @@ describe('Dialog', () => {
testViewContainerRef = viewContainerFixture.componentInstance.childViewContainer;
});

afterEach(() => overlayContainer.ngOnDestroy());

it('should open a dialog with a component', () => {
let dialogRef = dialog.openFromComponent(PizzaMsg, {
viewContainerRef: testViewContainerRef
Expand Down
14 changes: 1 addition & 13 deletions src/cdk-experimental/popover-edit/popover-edit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import {CdkTableModule} from '@angular/cdk/table';
import {dispatchKeyboardEvent} from '../../cdk/testing/private';
import {CommonModule} from '@angular/common';
import {Component, Directive, ElementRef, ViewChild} from '@angular/core';
import {ComponentFixture, fakeAsync, flush, TestBed, tick, inject} from '@angular/core/testing';
import {ComponentFixture, fakeAsync, flush, TestBed, tick} from '@angular/core/testing';
import {FormsModule, NgForm} from '@angular/forms';
import {BidiModule, Direction} from '@angular/cdk/bidi';
import {OverlayContainer} from '@angular/cdk/overlay';
import {BehaviorSubject} from 'rxjs';

import {
Expand Down Expand Up @@ -371,29 +370,18 @@ describe('CDK Popover Edit', () => {
describe(label, () => {
let component: BaseTestComponent;
let fixture: ComponentFixture<BaseTestComponent>;
let overlayContainer: OverlayContainer;

beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports: [CdkTableModule, CdkPopoverEditModule, CommonModule, FormsModule, BidiModule],
declarations: [componentClass],
}).compileComponents();
inject([OverlayContainer], (oc: OverlayContainer) => {
overlayContainer = oc;
})();
fixture = TestBed.createComponent<BaseTestComponent>(componentClass);
component = fixture.componentInstance;
fixture.detectChanges();
tick(10);
}));

afterEach(() => {
// The overlay container's `ngOnDestroy` won't be called between test runs so we need
// to call it ourselves, in order to avoid leaking containers between tests and potentially
// throwing off `querySelector` calls.
overlayContainer.ngOnDestroy();
});

describe('row hover content', () => {
it('makes the first and last rows focusable but invisible', fakeAsync(() => {
const rows = component.getRows();
Expand Down
4 changes: 0 additions & 4 deletions src/cdk/a11y/aria-describer/aria-describer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ describe('AriaDescriber', () => {
fixture.detectChanges();
}

afterEach(() => {
ariaDescriber.ngOnDestroy();
});

it('should initialize without the message container', () => {
createFixture();
expect(getMessagesContainer()).toBeNull();
Expand Down
4 changes: 0 additions & 4 deletions src/cdk/a11y/focus-monitor/focus-monitor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,13 @@ describe('FocusMonitor', () => {
tick();

expect(buttonElement.classList.length)

.withContext('button should have exactly 2 focus classes')
.toBe(2);

focusMonitor.stopMonitoring(buttonElement);
fixture.detectChanges();

expect(buttonElement.classList.length)

.withContext('button should not have any focus classes')
.toBe(0);
}));
Expand All @@ -266,7 +264,6 @@ describe('FocusMonitor', () => {
tick();

expect(buttonElement.classList.length)

.withContext('button should have exactly 2 focus classes')
.toBe(2);

Expand All @@ -275,7 +272,6 @@ describe('FocusMonitor', () => {
fixture.detectChanges();

expect(buttonElement.classList.length)

.withContext('button should not have any focus classes')
.toBe(0);
}));
Expand Down
5 changes: 0 additions & 5 deletions src/cdk/a11y/input-modality/input-modality-detector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ describe('InputModalityDetector', () => {
detector = TestBed.inject(InputModalityDetector);
}

afterEach(() => {
detector?.ngOnDestroy();
detector = undefined!;
});

it('should do nothing on non-browser platforms', () => {
setupTest(false);
expect(detector.mostRecentModality).toBe(null);
Expand Down
13 changes: 0 additions & 13 deletions src/cdk/a11y/live-announcer/live-announcer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ describe('LiveAnnouncer', () => {
fixture = TestBed.createComponent(TestApp);
})));

afterEach(() => {
// In our tests we always remove the current live element, in
// order to avoid having multiple announcer elements in the DOM.
announcer.ngOnDestroy();
});

it('should correctly update the announce text', fakeAsync(() => {
let buttonElement = fixture.debugElement.query(By.css('button'))!.nativeElement;
buttonElement.click();
Expand Down Expand Up @@ -116,7 +110,6 @@ describe('LiveAnnouncer', () => {
}));

it('should ensure that there is only one live element at a time', fakeAsync(() => {
announcer.ngOnDestroy();
fixture.destroy();

TestBed.resetTestingModule().configureTestingModule({
Expand Down Expand Up @@ -278,12 +271,6 @@ describe('CdkAriaLive', () => {
flush();
})));

afterEach(fakeAsync(() => {
// In our tests we always remove the current live element, in
// order to avoid having multiple announcer elements in the DOM.
announcer.ngOnDestroy();
}));

it('should default politeness to polite', fakeAsync(() => {
fixture.componentInstance.content = 'New content';
fixture.detectChanges();
Expand Down
4 changes: 0 additions & 4 deletions src/cdk/drag-drop/drag-drop-registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ describe('DragDropRegistry', () => {
})();
}));

afterEach(() => {
registry.ngOnDestroy();
});

it('should be able to start dragging an item', () => {
const item = new DragItem();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {TestBed, inject} from '@angular/core/testing';
import {dispatchKeyboardEvent} from '../../testing/private';
import {ESCAPE} from '@angular/cdk/keycodes';
import {Component, NgModule} from '@angular/core';
import {OverlayModule, OverlayContainer, Overlay} from '../index';
import {OverlayModule, Overlay} from '../index';
import {OverlayKeyboardDispatcher} from './overlay-keyboard-dispatcher';
import {ComponentPortal} from '@angular/cdk/portal';

Expand All @@ -22,10 +22,6 @@ describe('OverlayKeyboardDispatcher', () => {
})();
});

afterEach(inject([OverlayContainer], (overlayContainer: OverlayContainer) => {
overlayContainer.ngOnDestroy();
}));

it('should track overlays in order as they are attached and detached', () => {
const overlayOne = overlay.create();
const overlayTwo = overlay.create();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {TestBed, inject, fakeAsync} from '@angular/core/testing';
import {Component, NgModule} from '@angular/core';
import {dispatchFakeEvent, dispatchMouseEvent} from '../../testing/private';
import {OverlayModule, OverlayContainer, Overlay} from '../index';
import {OverlayModule, Overlay} from '../index';
import {OverlayOutsideClickDispatcher} from './overlay-outside-click-dispatcher';
import {ComponentPortal} from '@angular/cdk/portal';

Expand All @@ -21,10 +21,6 @@ describe('OverlayOutsideClickDispatcher', () => {
})();
});

afterEach(inject([OverlayContainer], (overlayContainer: OverlayContainer) => {
overlayContainer.ngOnDestroy();
}));

it('should track overlays in order as they are attached and detached', () => {
const overlayOne = overlay.create();
const overlayTwo = overlay.create();
Expand Down
5 changes: 1 addition & 4 deletions src/cdk/overlay/fullscreen-overlay-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {Overlay, OverlayContainer, OverlayModule, FullscreenOverlayContainer} fr

describe('FullscreenOverlayContainer', () => {
let overlay: Overlay;
let overlayContainer: FullscreenOverlayContainer;
let fullscreenListeners: Set<Function>;
let fakeDocument: any;

Expand Down Expand Up @@ -58,13 +57,11 @@ describe('FullscreenOverlayContainer', () => {
}).compileComponents();
}));

beforeEach(inject([Overlay, OverlayContainer], (o: Overlay, oc: OverlayContainer) => {
beforeEach(inject([Overlay], (o: Overlay) => {
overlay = o;
overlayContainer = oc as FullscreenOverlayContainer;
}));

afterEach(() => {
overlayContainer.ngOnDestroy();
fakeDocument = null;
});

Expand Down
4 changes: 0 additions & 4 deletions src/cdk/overlay/overlay-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ describe('OverlayContainer', () => {
overlayContainer = oc;
}));

afterEach(() => {
overlayContainer.ngOnDestroy();
});

it('should remove the overlay container element from the DOM on destruction', () => {
const fixture = TestBed.createComponent(TestComponentWithTemplatePortals);
fixture.detectChanges();
Expand Down
6 changes: 0 additions & 6 deletions src/cdk/overlay/overlay-directives.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {Subject} from 'rxjs';

describe('Overlay directives', () => {
let overlay: Overlay;
let overlayContainer: OverlayContainer;
let overlayContainerElement: HTMLElement;
let fixture: ComponentFixture<ConnectedOverlayDirectiveTest>;
let dir: {value: string};
Expand All @@ -61,15 +60,10 @@ describe('Overlay directives', () => {
});

beforeEach(inject([OverlayContainer, Overlay], (oc: OverlayContainer, o: Overlay) => {
overlayContainer = oc;
overlay = o;
overlayContainerElement = oc.getContainerElement();
}));

afterEach(() => {
overlayContainer.ngOnDestroy();
});

/** Returns the current open overlay pane element. */
function getPaneElement() {
return overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
Expand Down
14 changes: 5 additions & 9 deletions src/cdk/overlay/position/global-position-strategy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {NgModule, NgZone, Component} from '@angular/core';
import {TestBed, inject} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
import {MockNgZone} from '../../testing/private';
import {PortalModule, ComponentPortal} from '@angular/cdk/portal';
import {OverlayModule, Overlay, OverlayConfig, OverlayRef, OverlayContainer} from '../index';
import {OverlayModule, Overlay, OverlayConfig, OverlayRef} from '../index';


describe('GlobalPositonStrategy', () => {
Expand All @@ -16,19 +16,15 @@ describe('GlobalPositonStrategy', () => {
providers: [{provide: NgZone, useFactory: () => zone = new MockNgZone()}]
});

inject([Overlay], (o: Overlay) => {
overlay = o;
})();
overlay = TestBed.inject(Overlay);
});

afterEach(inject([OverlayContainer], (overlayContainer: OverlayContainer) => {
afterEach(() => {
if (overlayRef) {
overlayRef.dispose();
overlayRef = null!;
}

overlayContainer.ngOnDestroy();
}));
});

function attachOverlay(config: OverlayConfig): OverlayRef {
const portal = new ComponentPortal(BlankPortal);
Expand Down
4 changes: 0 additions & 4 deletions src/cdk/scrolling/viewport-ruler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ describe('ViewportRuler', () => {
scrollTo(0, 0);
}));

afterEach(() => {
viewportRuler.ngOnDestroy();
});

it('should get the viewport size', () => {
let size = viewportRuler.getViewportSize();
expect(size.width).toBe(window.innerWidth);
Expand Down
5 changes: 0 additions & 5 deletions src/cdk/text-field/autofill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ describe('AutofillMonitor', () => {
}
}));

afterEach(() => {
// Call destroy to make sure we clean up all listeners.
autofillMonitor.ngOnDestroy();
});

it('should add monitored class and listener upon monitoring', () => {
const inputEl = testComponent.input1.nativeElement;
expect(inputEl.addEventListener).not.toHaveBeenCalled();
Expand Down
14 changes: 1 addition & 13 deletions src/material-experimental/column-resize/column-resize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import {
ViewChild,
ChangeDetectionStrategy,
} from '@angular/core';
import {ComponentFixture, TestBed, fakeAsync, flushMicrotasks, inject} from '@angular/core/testing';
import {ComponentFixture, TestBed, fakeAsync, flushMicrotasks} from '@angular/core/testing';
import {BidiModule} from '@angular/cdk/bidi';
import {DataSource} from '@angular/cdk/collections';
import {dispatchKeyboardEvent} from '../../cdk/testing/private';
import {ESCAPE} from '@angular/cdk/keycodes';
import {OverlayContainer} from '@angular/cdk/overlay';
import {MatTableModule} from '@angular/material/table';
import {BehaviorSubject} from 'rxjs';

Expand Down Expand Up @@ -348,7 +347,6 @@ describe('Material Popover Edit', () => {
describe(label, () => {
let component: BaseTestComponent;
let fixture: ComponentFixture<BaseTestComponent>;
let overlayContainer: OverlayContainer;

beforeEach(fakeAsync(() => {
jasmine.addMatchers(approximateMatcher);
Expand All @@ -357,22 +355,12 @@ describe('Material Popover Edit', () => {
imports: [BidiModule, MatTableModule, resizeModule],
declarations: [componentClass],
}).compileComponents();
inject([OverlayContainer], (oc: OverlayContainer) => {
overlayContainer = oc;
})();
fixture = TestBed.createComponent(componentClass);
component = fixture.componentInstance;
fixture.detectChanges();
flushMicrotasks();
}));

afterEach(() => {
// The overlay container's `ngOnDestroy` won't be called between test runs so we need
// to call it ourselves, in order to avoid leaking containers between tests and potentially
// throwing `querySelector` calls.
overlayContainer.ngOnDestroy();
});

it('shows resize handle overlays on header row hover and while a resize handle is in use',
fakeAsync(() => {
expect(component.getOverlayThumbElement(0)).toBeUndefined();
Expand Down
Loading