diff --git a/src/lib/tooltip/tooltip.spec.ts b/src/lib/tooltip/tooltip.spec.ts index 6421cde3f52c..4ca63913de1d 100644 --- a/src/lib/tooltip/tooltip.spec.ts +++ b/src/lib/tooltip/tooltip.spec.ts @@ -74,6 +74,30 @@ describe('MdTooltip', () => { expect(tooltipDirective._tooltipInstance).toBeNull(); })); + it('should not show tooltip if message is not present or empty', fakeAsync(() => { + expect(tooltipDirective._tooltipInstance).toBeUndefined(); + + tooltipDirective.message = undefined; + fixture.detectChanges(); + tooltipDirective.show(); + expect(tooltipDirective._tooltipInstance).toBeUndefined(); + + tooltipDirective.message = null; + fixture.detectChanges(); + tooltipDirective.show(); + expect(tooltipDirective._tooltipInstance).toBeUndefined(); + + tooltipDirective.message = ''; + fixture.detectChanges(); + tooltipDirective.show(); + expect(tooltipDirective._tooltipInstance).toBeUndefined(); + + tooltipDirective.message = ' '; + fixture.detectChanges(); + tooltipDirective.show(); + expect(tooltipDirective._tooltipInstance).toBeUndefined(); + })); + it('should not follow through with hide if show is called after', fakeAsync(() => { tooltipDirective.show(); expect(tooltipDirective._isTooltipVisible()).toBe(true); diff --git a/src/lib/tooltip/tooltip.ts b/src/lib/tooltip/tooltip.ts index cd46c7891f35..96c3d0d66dfd 100644 --- a/src/lib/tooltip/tooltip.ts +++ b/src/lib/tooltip/tooltip.ts @@ -98,6 +98,10 @@ export class MdTooltip { /** Shows the tooltip */ show(): void { + if (!this._message || !this._message.trim()) { + return; + } + if (!this._tooltipInstance) { this._createTooltip(); }