From: Hiws Date: Thu, 24 Sep 2020 11:55:38 +0000 (+0200) Subject: fix tooltip hide method when already hidden (#31115) X-Git-Tag: v5.0.0-alpha2~28 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=43b4252a3487e419455f794e16d402a32d1ebe22;p=thirdparty%2Fbootstrap.git fix tooltip hide method when already hidden (#31115) Co-authored-by: XhmikosR --- diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 9ad73328be..1bda97e388 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -331,6 +331,10 @@ class Tooltip { } hide() { + if (!this._popper) { + return + } + const tip = this.getTipElement() const complete = () => { if (this._hoverState !== HOVER_STATE_SHOW && tip.parentNode) { diff --git a/js/tests/unit/tooltip.spec.js b/js/tests/unit/tooltip.spec.js index 0a98096a40..3e5c917940 100644 --- a/js/tests/unit/tooltip.spec.js +++ b/js/tests/unit/tooltip.spec.js @@ -717,6 +717,20 @@ describe('Tooltip', () => { tooltip.show() }) + + it('should not throw error running hide if popper hasn\'t been shown', () => { + fixtureEl.innerHTML = '
' + + const div = fixtureEl.querySelector('div') + const tooltip = new Tooltip(div) + + try { + tooltip.hide() + expect().nothing() + } catch { + throw new Error('should not throw error') + } + }) }) describe('update', () => {