Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRohit Sharma <rohit2sharma95@gmail.com>2020-07-15 15:39:04 +0300
committerXhmikosR <xhmikosr@gmail.com>2020-08-03 19:06:36 +0300
commit1abe9264aa867766a1dd1d393fe4650a30d17e31 (patch)
tree3302c4f3163d2dcdb0442719ea1718c0d280eae2
parentf530ab7549e76a9faa5285edcd0d42ea8a30a6bf (diff)
Add unit test for toast to check clearTimeout to have been called (#31298)
-rw-r--r--js/tests/unit/toast.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/js/tests/unit/toast.js b/js/tests/unit/toast.js
index 89bcaf9b64..a4c6560b88 100644
--- a/js/tests/unit/toast.js
+++ b/js/tests/unit/toast.js
@@ -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()