Skip to content
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

fix(menu,tooltip): Ensure subscription exists before unsubscribing. #3078

Merged
merged 1 commit into from
Mar 9, 2017
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: 3 additions & 1 deletion src/lib/menu/menu-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
}

ngOnDestroy() {
this._tabSubscription.unsubscribe();
if (this._tabSubscription) {
this._tabSubscription.unsubscribe();
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/lib/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ describe('MdMenu', () => {

});

describe('destroy', () => {
it('does not throw an error on destroy', () => {
const fixture = TestBed.createComponent(SimpleMenu);
expect(fixture.destroy.bind(fixture)).not.toThrow();
});
});
});

@Component({
Expand Down
10 changes: 10 additions & 0 deletions src/lib/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ describe('MdTooltip', () => {
expect(tooltipDirective._tooltipInstance).toBeNull();
}));
});

describe('destroy', () => {
it('does not throw an error on destroy', () => {
const fixture = TestBed.createComponent(BasicTooltipDemo);
fixture.detectChanges();
delete fixture.componentInstance.tooltip.scrollSubscription;
expect(fixture.destroy.bind(fixture)).not.toThrow();
});
});
});

@Component({
Expand All @@ -413,6 +422,7 @@ class BasicTooltipDemo {
position: string = 'below';
message: string = initialTooltipMessage;
showButton: boolean = true;
@ViewChild(MdTooltip) tooltip: MdTooltip;
}

@Component({
Expand Down
4 changes: 3 additions & 1 deletion src/lib/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ export class MdTooltip implements OnInit, OnDestroy {
this._disposeTooltip();
}

this.scrollSubscription.unsubscribe();
if (this.scrollSubscription) {
this.scrollSubscription.unsubscribe();
}
}

/** Shows the tooltip after the delay in ms, defaults to tooltip-delay-show or 0ms if no input */
Expand Down