Skip to content

Commit

Permalink
Tooltip - check if tip and its parent node exist in dispose method (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit2sharma95 committed Dec 10, 2020
1 parent 1edec54 commit 4535b09
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/tooltip.js
Expand Up @@ -222,7 +222,7 @@ class Tooltip extends BaseComponent {
EventHandler.off(this._element, this.constructor.EVENT_KEY)
EventHandler.off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler)

if (this.tip) {
if (this.tip && this.tip.parentNode) {
this.tip.parentNode.removeChild(this.tip)
}

Expand Down
18 changes: 18 additions & 0 deletions js/tests/unit/tooltip.spec.js
Expand Up @@ -286,6 +286,24 @@ describe('Tooltip', () => {
expect(Tooltip.getInstance(tooltipEl)).toEqual(null)
})

it('should destroy a tooltip after it is shown and hidden', () => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip">'

const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)

tooltipEl.addEventListener('shown.bs.tooltip', () => {
tooltip.hide()
})
tooltipEl.addEventListener('hidden.bs.tooltip', () => {
tooltip.dispose()
expect(tooltip.tip).toEqual(null)
expect(Tooltip.getInstance(tooltipEl)).toEqual(null)
})

tooltip.show()
})

it('should destroy a tooltip and remove it from the dom', done => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip">'

Expand Down

0 comments on commit 4535b09

Please sign in to comment.