diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 6c23b9f9dde7..c4fdbff59c66 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -239,6 +239,9 @@ const Tooltip = (($) => { } show() { + if ($(this.element).css('display') === 'none') { + throw new Error('Please use show on visible elements') + } let showEvent = $.Event(this.constructor.Event.SHOW) if (this.isWithContent() && this._isEnabled) { diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index 1808ff50aa6d..6e47222f14ce 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -320,4 +320,16 @@ $(function () { .bootstrapPopover('show') }) + QUnit.test('should throw an error when show is called on hidden elements', function (assert) { + assert.expect(1) + var done = assert.async() + + try { + $('
').bootstrapPopover('show') + } + catch (err) { + assert.strictEqual(err.message, 'Please use show on visible elements') + done() + } + }) }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index de313ff953f9..97c5855cb08a 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -185,6 +185,19 @@ $(function () { .bootstrapTooltip('show') }) + QUnit.test('should throw an error when show is called on hidden elements', function (assert) { + assert.expect(1) + var done = assert.async() + + try { + $('').bootstrapTooltip('show') + } + catch (err) { + assert.strictEqual(err.message, 'Please use show on visible elements') + done() + } + }) + QUnit.test('should fire inserted event', function (assert) { assert.expect(2) var done = assert.async()