Skip to content

Commit 968755b

Browse files
rohit2sharma95XhmikosR
authored andcommitted
Add unit test for toast to check clearTimeout to have been called (#31298)
1 parent 2cbe9b1 commit 968755b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

js/tests/unit/toast.js

+31
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,37 @@ $(function () {
290290
.bootstrapToast('show')
291291
})
292292

293+
QUnit.test('should clear timeout if toast is shown again before it is hidden', function (assert) {
294+
assert.expect(2)
295+
var done = assert.async()
296+
297+
var toastHtml =
298+
'<div class="toast">' +
299+
'<div class="toast-body">' +
300+
'a simple toast' +
301+
'</div>' +
302+
'</div>'
303+
304+
var $toast = $(toastHtml)
305+
.bootstrapToast()
306+
.appendTo($('#qunit-fixture'))
307+
308+
var toast = $toast.data('bs.toast')
309+
var spyClearTimeout = sinon.spy(toast, '_clearTimeout')
310+
311+
setTimeout(function () {
312+
toast._config.autohide = false
313+
$toast.on('shown.bs.toast', function () {
314+
assert.ok(spyClearTimeout.called)
315+
assert.ok(toast._timeout === null)
316+
done()
317+
})
318+
$toast.bootstrapToast('show')
319+
}, toast._config.delay / 2)
320+
321+
$toast.bootstrapToast('show')
322+
})
323+
293324
QUnit.test('should not trigger hidden if hide is prevented', function (assert) {
294325
assert.expect(1)
295326
var done = assert.async()

0 commit comments

Comments
 (0)