diff options
author | Johann <johann.servoire@gmail.com> | 2016-11-01 06:33:53 +0300 |
---|---|---|
committer | Mark Otto <markd.otto@gmail.com> | 2016-11-01 06:33:53 +0300 |
commit | a7f1b59959b12ab2e78c32e6954d083601ad45ba (patch) | |
tree | 031ec6da859411b97efa52a549e4cbfc15b791dd | |
parent | 0974267b8c2b137d563d36c2390b4491fb1e0309 (diff) |
Making .tooltip('show') throw an error on elements with display:none (#20940)
-rw-r--r-- | js/src/tooltip.js | 3 | ||||
-rw-r--r-- | js/tests/unit/popover.js | 12 | ||||
-rw-r--r-- | js/tests/unit/tooltip.js | 13 |
3 files changed, 28 insertions, 0 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 6c23b9f9dd..c4fdbff59c 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 1808ff50aa..6e47222f14 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 { + $('<div data-toggle="popover" data-title="some title" data-content="@Johann-S" style="display: none"/>').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 de313ff953..97c5855cb0 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 { + $('<div title="tooltip title" style="display: none"/>').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() |