Skip to content

Commit 7884b09

Browse files
crisbetoandrewseguin
authored andcommitted
chore: random test leaks (#4380)
Fixes some unit tests that were leaking elements into other tests.
1 parent c37a2de commit 7884b09

File tree

7 files changed

+25
-1
lines changed

7 files changed

+25
-1
lines changed

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ describe('MdAutocomplete', () => {
8080
TestBed.compileComponents();
8181
}));
8282

83+
afterEach(() => {
84+
document.body.removeChild(overlayContainerElement);
85+
});
86+
8387
describe('panel toggling', () => {
8488
let fixture: ComponentFixture<SimpleAutocomplete>;
8589
let input: HTMLInputElement;

src/lib/core/overlay/overlay.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ describe('OverlayContainer theming', () => {
393393
overlayContainerElement = overlayContainer.getContainerElement();
394394
}));
395395

396+
afterEach(() => {
397+
overlayContainerElement.parentNode.removeChild(overlayContainerElement);
398+
});
399+
396400
it('should be able to set a theme on the overlay container', () => {
397401
overlayContainer.themeClass = 'my-theme';
398402
expect(overlayContainerElement.classList).toContain('my-theme');

src/lib/core/overlay/position/global-position-strategy.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('GlobalPositonStrategy', () => {
1717
});
1818

1919
afterEach(() => {
20+
element.parentNode.removeChild(element);
2021
strategy.dispose();
2122
});
2223

src/lib/core/overlay/scroll/close-scroll-strategy.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ describe('CloseScrollStrategy', () => {
4343
componentPortal = new ComponentPortal(MozarellaMsg);
4444
}));
4545

46+
afterEach(() => {
47+
overlayRef.dispose();
48+
});
49+
4650
it('should detach the overlay as soon as the user scrolls', () => {
4751
overlayRef.attach(componentPortal);
4852
spyOn(overlayRef, 'detach');

src/lib/core/overlay/scroll/reposition-scroll-strategy.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ describe('RepositionScrollStrategy', () => {
4343
componentPortal = new ComponentPortal(PastaMsg);
4444
}));
4545

46+
afterEach(() => {
47+
overlayRef.dispose();
48+
});
49+
4650
it('should update the overlay position when the page is scrolled', () => {
4751
overlayRef.attach(componentPortal);
4852
spyOn(overlayRef, 'updatePosition');

src/lib/snack-bar/snack-bar.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ describe('MdSnackBar with parent MdSnackBar', () => {
349349
let childSnackBar: MdSnackBar;
350350
let overlayContainerElement: HTMLElement;
351351
let fixture: ComponentFixture<ComponentThatProvidesMdSnackBar>;
352+
let liveAnnouncer: LiveAnnouncer;
352353

353354
beforeEach(async(() => {
354355
TestBed.configureTestingModule({
@@ -365,8 +366,9 @@ describe('MdSnackBar with parent MdSnackBar', () => {
365366
TestBed.compileComponents();
366367
}));
367368

368-
beforeEach(inject([MdSnackBar], (sb: MdSnackBar) => {
369+
beforeEach(inject([MdSnackBar, LiveAnnouncer], (sb: MdSnackBar, la: LiveAnnouncer) => {
369370
parentSnackBar = sb;
371+
liveAnnouncer = la;
370372

371373
fixture = TestBed.createComponent(ComponentThatProvidesMdSnackBar);
372374
childSnackBar = fixture.componentInstance.snackBar;
@@ -375,6 +377,7 @@ describe('MdSnackBar with parent MdSnackBar', () => {
375377

376378
afterEach(() => {
377379
overlayContainerElement.innerHTML = '';
380+
liveAnnouncer._removeLiveElement();
378381
});
379382

380383
it('should close snackBars opened by parent when opening from child MdSnackBar', fakeAsync(() => {

src/lib/tooltip/tooltip.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ describe('MdTooltip', () => {
5050
TestBed.compileComponents();
5151
}));
5252

53+
afterEach(() => {
54+
document.body.removeChild(overlayContainerElement);
55+
});
56+
5357
describe('basic usage', () => {
5458
let fixture: ComponentFixture<BasicTooltipDemo>;
5559
let buttonDebugElement: DebugElement;

0 commit comments

Comments
 (0)