Skip to content

Commit

Permalink
fix(menu,tooltip): Ensure subscription exists before unsubscribing. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
trshafer authored and tinayuangao committed Mar 9, 2017
1 parent 5d6920d commit 84b5c3b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/lib/menu/menu-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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 @@ -402,6 +402,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 @@ -417,6 +426,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 @@ -161,7 +161,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

0 comments on commit 84b5c3b

Please sign in to comment.