mirror of
https://github.com/twbs/bootstrap.git
synced 2024-11-29 11:24:18 +01:00
Add unit test for toast to check clearTimeout to have been called (#31298)
This commit is contained in:
parent
f530ab7549
commit
1abe9264aa
@ -290,6 +290,37 @@ $(function () {
|
|||||||
.bootstrapToast('show')
|
.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) {
|
QUnit.test('should not trigger hidden if hide is prevented', function (assert) {
|
||||||
assert.expect(1)
|
assert.expect(1)
|
||||||
var done = assert.async()
|
var done = assert.async()
|
||||||
|
Loading…
Reference in New Issue
Block a user