Skip to content

Commit

Permalink
Making .tooltip('show') throw an error on elements with display:none (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S authored and mdo committed Nov 1, 2016
1 parent 0974267 commit a7f1b59
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions js/tests/unit/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
})
13 changes: 13 additions & 0 deletions js/tests/unit/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a7f1b59

Please sign in to comment.