]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Add unit test for toast to check clearTimeout to have been called (#31298)
authorRohit Sharma <rohit2sharma95@gmail.com>
Wed, 15 Jul 2020 12:39:04 +0000 (18:09 +0530)
committerXhmikosR <xhmikosr@gmail.com>
Mon, 3 Aug 2020 16:06:36 +0000 (19:06 +0300)
js/tests/unit/toast.js

index 89bcaf9b6452e123e09665e87b392c4fdc55e419..a4c6560b88c8bc88f5ae6fd9c2afccdd507e5f04 100644 (file)
@@ -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()