]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
fix tooltip hide method when already hidden (#31115)
authorHiws <hiws@live.dk>
Thu, 24 Sep 2020 11:55:38 +0000 (13:55 +0200)
committerGitHub <noreply@github.com>
Thu, 24 Sep 2020 11:55:38 +0000 (14:55 +0300)
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
js/src/tooltip.js
js/tests/unit/tooltip.spec.js

index 9ad73328bed9fb214a8c9da82756ed58f517c3fb..1bda97e388caf614d6ceb52e9741ff1b9282e3e6 100644 (file)
@@ -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) {
index 0a98096a405ecc25e2c9e595f1bfcbefa1aaa78e..3e5c9179401b77e41af3ae84fb501c613d61b142 100644 (file)
@@ -717,6 +717,20 @@ describe('Tooltip', () => {
 
       tooltip.show()
     })
+
+    it('should not throw error running hide if popper hasn\'t been shown', () => {
+      fixtureEl.innerHTML = '<div></div>'
+
+      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', () => {