aboutsummaryrefslogtreecommitdiff
path: root/js/tests
diff options
context:
space:
mode:
authorJohann-S <[email protected]>2019-05-16 11:57:05 +0200
committerJohann-S <[email protected]>2019-05-16 13:24:29 +0200
commitd5752a18abdf2991ca97660ccdbf42c494d6878d (patch)
tree758c3240cbd4e6f38eb3ba552786d1a749c88411 /js/tests
parent4ea7e11233dee88a6243ae1893ca1cd5b8cbeac6 (diff)
downloadbootstrap-d5752a18abdf2991ca97660ccdbf42c494d6878d.tar.xz
bootstrap-d5752a18abdf2991ca97660ccdbf42c494d6878d.zip
toast should allow prevent default for hide and show events
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/unit/toast.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/js/tests/unit/toast.js b/js/tests/unit/toast.js
index 57f953bd1..234e5955c 100644
--- a/js/tests/unit/toast.js
+++ b/js/tests/unit/toast.js
@@ -255,4 +255,75 @@ $(function () {
var toast = Toast._getInstance($toast[0])
assert.strictEqual(toast._config.delay, defaultDelay)
})
+
+ QUnit.test('should not trigger shown if show is prevented', function (assert) {
+ assert.expect(1)
+ var done = assert.async()
+
+ var toastHtml =
+ '<div class="toast" data-delay="1" data-autohide="false">' +
+ '<div class="toast-body">' +
+ 'a simple toast' +
+ '</div>' +
+ '</div>'
+
+ var $toast = $(toastHtml)
+ .bootstrapToast()
+ .appendTo($('#qunit-fixture'))
+
+ var shownCalled = false
+ function assertDone() {
+ setTimeout(function () {
+ assert.strictEqual(shownCalled, false)
+ done()
+ }, 20)
+ }
+
+ $toast
+ .on('show.bs.toast', function (event) {
+ event.preventDefault()
+ assertDone()
+ })
+ .on('shown.bs.toast', function () {
+ shownCalled = true
+ })
+ .bootstrapToast('show')
+ })
+
+ QUnit.test('should not trigger hidden if hide is prevented', function (assert) {
+ assert.expect(1)
+ var done = assert.async()
+
+ var toastHtml =
+ '<div class="toast" data-delay="1" data-autohide="false">' +
+ '<div class="toast-body">' +
+ 'a simple toast' +
+ '</div>' +
+ '</div>'
+
+ var $toast = $(toastHtml)
+ .bootstrapToast()
+ .appendTo($('#qunit-fixture'))
+
+ var hiddenCalled = false
+ function assertDone() {
+ setTimeout(function () {
+ assert.strictEqual(hiddenCalled, false)
+ done()
+ }, 20)
+ }
+
+ $toast
+ .on('shown.bs.toast', function () {
+ $toast.bootstrapToast('hide')
+ })
+ .on('hide.bs.toast', function (event) {
+ event.preventDefault()
+ assertDone()
+ })
+ .on('hidden.bs.toast', function () {
+ hiddenCalled = true
+ })
+ .bootstrapToast('show')
+ })
})