Skip to content

Commit

Permalink
Add unit test for toast to check clearTimeout to have been called (#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit2sharma95 authored and XhmikosR committed Aug 3, 2020
1 parent f530ab7 commit 1abe926
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions js/tests/unit/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,37 @@ $(function () {
.bootstrapToast('show')
})

QUnit.test('should clear timeout if toast is shown again before it is hidden', function (assert) {
assert.expect(2)
var done = assert.async()

var toastHtml =
'<div class="toast">' +
'<div class="toast-body">' +
'a simple toast' +
'</div>' +
'</div>'

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

var toast = $toast.data('bs.toast')
var spyClearTimeout = sinon.spy(toast, '_clearTimeout')

setTimeout(function () {
toast._config.autohide = false
$toast.on('shown.bs.toast', function () {
assert.ok(spyClearTimeout.called)
assert.ok(toast._timeout === null)
done()
})
$toast.bootstrapToast('show')
}, toast._config.delay / 2)

$toast.bootstrapToast('show')
})

QUnit.test('should not trigger hidden if hide is prevented', function (assert) {
assert.expect(1)
var done = assert.async()
Expand Down

0 comments on commit 1abe926

Please sign in to comment.