Skip to content

Commit

Permalink
hide toast on dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S authored and XhmikosR committed Sep 18, 2018
1 parent 54f8bc8 commit d683448
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions js/src/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ const Toast = (($) => {

dispose() {
clearTimeout(this._timeout)
this._timeout = null

if (this._element.classList.contains(ClassName.SHOW)) {
this._element.classList.remove(ClassName.SHOW)
}

$.removeData(this._element, DATA_KEY)
this._element = null
this._config = null
Expand Down
31 changes: 31 additions & 0 deletions js/tests/unit/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,37 @@ $(function () {
assert.ok(typeof $toast.data('bs.toast') === 'undefined')
})

QUnit.test('should allow to destroy toast and hide it before that', function (assert) {
assert.expect(4)
var done = assert.async()

var toastHtml =
'<div class="toast" data-delay="0" data-autohide="false">' +
'<div class="toast-body">' +
'a simple toast' +
'</div>' +
'</div>'

var $toast = $(toastHtml)
.bootstrapToast()
.appendTo($('#qunit-fixture'))

$toast.one('shown.bs.toast', function () {
setTimeout(function () {
assert.ok($toast.hasClass('show'))
assert.ok(typeof $toast.data('bs.toast') !== 'undefined')

$toast.bootstrapToast('dispose')

assert.ok(typeof $toast.data('bs.toast') === 'undefined')
assert.ok($toast.hasClass('show') === false)

done()
}, 1)
})
.bootstrapToast('show')
})

QUnit.test('should allow to pass delay object in html', function (assert) {
assert.expect(1)
var done = assert.async()
Expand Down

0 comments on commit d683448

Please sign in to comment.