diff --git a/src/lib/tooltip/tooltip.spec.ts b/src/lib/tooltip/tooltip.spec.ts index 05e894fc504c..8f1a4ccc5746 100644 --- a/src/lib/tooltip/tooltip.spec.ts +++ b/src/lib/tooltip/tooltip.spec.ts @@ -70,6 +70,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 a9621d78840f..28910d203b78 100644 --- a/src/lib/tooltip/tooltip.ts +++ b/src/lib/tooltip/tooltip.ts @@ -96,6 +96,10 @@ export class MdTooltip { /** Shows the tooltip */ show(): void { + if (!this._message || !this._message.trim()) { + return; + } + if (!this._tooltipInstance) { this._createTooltip(); }