]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Tooltip - check if tip and its parent node exist in dispose method (#32420)
authorRohit Sharma <rohit2sharma95@gmail.com>
Thu, 10 Dec 2020 19:06:41 +0000 (00:36 +0530)
committerGitHub <noreply@github.com>
Thu, 10 Dec 2020 19:06:41 +0000 (21:06 +0200)
js/src/tooltip.js
js/tests/unit/tooltip.spec.js

index 4eb4fde0bf0fb80a1246c9de3a1ddc562ff5f7f7..103524b8b49f04df4507d2782dd3c0a9ea28427d 100644 (file)
@@ -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)
     }
 
index 9fc306dfe174327cc49b7d5710d253e161efbb81..2b20d7e11743620a34c9dc7e3add17e7a267192f 100644 (file)
@@ -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">'