Skip to content

Commit 2f89343

Browse files
Johann-SXhmikosR
authored andcommitted
hide toast on dispose
1 parent eddd170 commit 2f89343

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

js/src/toast.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ const Toast = (($) => {
132132

133133
dispose() {
134134
clearTimeout(this._timeout)
135+
this._timeout = null
136+
137+
if (this._element.classList.contains(ClassName.SHOW)) {
138+
this._element.classList.remove(ClassName.SHOW)
139+
}
140+
135141
$.removeData(this._element, DATA_KEY)
136142
this._element = null
137143
this._config = null

js/tests/unit/toast.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,37 @@ $(function () {
153153
assert.ok(typeof $toast.data('bs.toast') === 'undefined')
154154
})
155155

156+
QUnit.test('should allow to destroy toast and hide it before that', function (assert) {
157+
assert.expect(4)
158+
var done = assert.async()
159+
160+
var toastHtml =
161+
'<div class="toast" data-delay="0" data-autohide="false">' +
162+
'<div class="toast-body">' +
163+
'a simple toast' +
164+
'</div>' +
165+
'</div>'
166+
167+
var $toast = $(toastHtml)
168+
.bootstrapToast()
169+
.appendTo($('#qunit-fixture'))
170+
171+
$toast.one('shown.bs.toast', function () {
172+
setTimeout(function () {
173+
assert.ok($toast.hasClass('show'))
174+
assert.ok(typeof $toast.data('bs.toast') !== 'undefined')
175+
176+
$toast.bootstrapToast('dispose')
177+
178+
assert.ok(typeof $toast.data('bs.toast') === 'undefined')
179+
assert.ok($toast.hasClass('show') === false)
180+
181+
done()
182+
}, 1)
183+
})
184+
.bootstrapToast('show')
185+
})
186+
156187
QUnit.test('should allow to pass delay object in html', function (assert) {
157188
assert.expect(1)
158189
var done = assert.async()

0 commit comments

Comments
 (0)