mirror of
https://github.com/tenrok/bootstrap.git
synced 2026-06-08 17:22:31 +03:00
tests: comply to the new rules
Use `assert.strictEqual`/`assert.true`/`assert.false`
This commit is contained in:
+49
-47
@@ -53,7 +53,7 @@ $(function () {
|
||||
assert.expect(2)
|
||||
var $el = $('<div id="modal-test"/>')
|
||||
var $modal = $el.bootstrapModal()
|
||||
assert.ok($modal instanceof $, 'returns jquery collection')
|
||||
assert.true($modal instanceof $, 'returns jquery collection')
|
||||
assert.strictEqual($modal[0], $el[0], 'collection contains element')
|
||||
})
|
||||
|
||||
@@ -121,8 +121,8 @@ $(function () {
|
||||
}
|
||||
})
|
||||
.on('shown.bs.modal', function () {
|
||||
assert.ok(prevented, 'show prevented')
|
||||
assert.ok($el.hasClass('fade'))
|
||||
assert.true(prevented, 'show prevented')
|
||||
assert.true($el.hasClass('fade'))
|
||||
done()
|
||||
})
|
||||
.bootstrapModal('show')
|
||||
@@ -134,12 +134,12 @@ $(function () {
|
||||
|
||||
$('<div id="modal-test"/>')
|
||||
.on('shown.bs.modal', function () {
|
||||
assert.ok($('#modal-test').is(':visible'), 'modal visible')
|
||||
assert.true($('#modal-test').is(':visible'), 'modal visible')
|
||||
assert.notStrictEqual($('#modal-test').length, 0, 'modal inserted into dom')
|
||||
$(this).bootstrapModal('hide')
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
||||
assert.false($('#modal-test').is(':visible'), 'modal hidden')
|
||||
done()
|
||||
})
|
||||
.bootstrapModal('show')
|
||||
@@ -151,12 +151,12 @@ $(function () {
|
||||
|
||||
$('<div id="modal-test"/>')
|
||||
.on('shown.bs.modal', function () {
|
||||
assert.ok($('#modal-test').is(':visible'), 'modal visible')
|
||||
assert.true($('#modal-test').is(':visible'), 'modal visible')
|
||||
assert.notStrictEqual($('#modal-test').length, 0, 'modal inserted into dom')
|
||||
$(this).bootstrapModal('toggle')
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
||||
assert.false($('#modal-test').is(':visible'), 'modal hidden')
|
||||
done()
|
||||
})
|
||||
.bootstrapModal('toggle')
|
||||
@@ -168,12 +168,12 @@ $(function () {
|
||||
|
||||
$('<div id="modal-test"><span class="close" data-dismiss="modal"/></div>')
|
||||
.on('shown.bs.modal', function () {
|
||||
assert.ok($('#modal-test').is(':visible'), 'modal visible')
|
||||
assert.true($('#modal-test').is(':visible'), 'modal visible')
|
||||
assert.notStrictEqual($('#modal-test').length, 0, 'modal inserted into dom')
|
||||
$(this).find('.close').trigger('click')
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
||||
assert.false($('#modal-test').is(':visible'), 'modal hidden')
|
||||
done()
|
||||
})
|
||||
.bootstrapModal('toggle')
|
||||
@@ -185,11 +185,11 @@ $(function () {
|
||||
|
||||
$('<div id="modal-test" data-backdrop="false"/>')
|
||||
.on('shown.bs.modal', function () {
|
||||
assert.ok($('#modal-test').is(':visible'), 'modal visible')
|
||||
assert.true($('#modal-test').is(':visible'), 'modal visible')
|
||||
$(this).bootstrapModal('hide')
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
||||
assert.false($('#modal-test').is(':visible'), 'modal hidden')
|
||||
done()
|
||||
})
|
||||
.bootstrapModal('show')
|
||||
@@ -203,11 +203,11 @@ $(function () {
|
||||
.on('shown.bs.modal', function () {
|
||||
assert.notStrictEqual($('#modal-test').length, 0, 'modal inserted into dom')
|
||||
$('.contents').trigger('click')
|
||||
assert.ok($('#modal-test').is(':visible'), 'modal visible')
|
||||
assert.true($('#modal-test').is(':visible'), 'modal visible')
|
||||
$('#modal-test').trigger('click')
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
||||
assert.false($('#modal-test').is(':visible'), 'modal hidden')
|
||||
done()
|
||||
})
|
||||
.bootstrapModal('show')
|
||||
@@ -220,7 +220,7 @@ $(function () {
|
||||
$('<div id="modal-test" data-backdrop="false"><div class="contents"/></div>')
|
||||
.on('shown.bs.modal', function () {
|
||||
$('#modal-test').trigger('click')
|
||||
assert.ok($('#modal-test').is(':visible'), 'modal not hidden')
|
||||
assert.true($('#modal-test').is(':visible'), 'modal not hidden')
|
||||
done()
|
||||
})
|
||||
.bootstrapModal('show')
|
||||
@@ -233,14 +233,14 @@ $(function () {
|
||||
var $div = $('<div id="modal-test"/>')
|
||||
$div
|
||||
.on('shown.bs.modal', function () {
|
||||
assert.ok($('#modal-test').length, 'modal inserted into dom')
|
||||
assert.ok($('#modal-test').is(':visible'), 'modal visible')
|
||||
assert.notStrictEqual($('#modal-test').length, 0, 'modal inserted into dom')
|
||||
assert.true($('#modal-test').is(':visible'), 'modal visible')
|
||||
$div.trigger($.Event('keydown', {
|
||||
which: 27
|
||||
}))
|
||||
|
||||
setTimeout(function () {
|
||||
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
||||
assert.false($('#modal-test').is(':visible'), 'modal hidden')
|
||||
$div.remove()
|
||||
done()
|
||||
}, 0)
|
||||
@@ -255,14 +255,14 @@ $(function () {
|
||||
var $div = $('<div id="modal-test"/>')
|
||||
$div
|
||||
.on('shown.bs.modal', function () {
|
||||
assert.ok($('#modal-test').length, 'modal inserted into dom')
|
||||
assert.ok($('#modal-test').is(':visible'), 'modal visible')
|
||||
assert.notStrictEqual($('#modal-test').length, 0, 'modal inserted into dom')
|
||||
assert.true($('#modal-test').is(':visible'), 'modal visible')
|
||||
$div.trigger($.Event('keyup', {
|
||||
which: 27
|
||||
}))
|
||||
|
||||
setTimeout(function () {
|
||||
assert.ok($div.is(':visible'), 'modal still visible')
|
||||
assert.true($div.is(':visible'), 'modal still visible')
|
||||
$div.remove()
|
||||
done()
|
||||
}, 0)
|
||||
@@ -295,11 +295,11 @@ $(function () {
|
||||
|
||||
$('<div id="modal-test" aria-hidden="true"/>')
|
||||
.on('shown.bs.modal', function () {
|
||||
assert.notOk($('#modal-test').is('[aria-hidden]'), 'aria-hidden attribute removed')
|
||||
assert.false($('#modal-test').is('[aria-hidden]'), 'aria-hidden attribute removed')
|
||||
$(this).bootstrapModal('hide')
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
assert.ok($('#modal-test').is('[aria-hidden]'), 'aria-hidden attribute added')
|
||||
assert.true($('#modal-test').is('[aria-hidden]'), 'aria-hidden attribute added')
|
||||
assert.strictEqual($('#modal-test').attr('aria-hidden'), 'true', 'correct aria-hidden="true" added')
|
||||
done()
|
||||
})
|
||||
@@ -312,12 +312,12 @@ $(function () {
|
||||
|
||||
$('<div id="modal-test"/>')
|
||||
.on('shown.bs.modal', function () {
|
||||
assert.ok($('#modal-test').is('[aria-modal]'), 'aria-modal attribute added')
|
||||
assert.true($('#modal-test').is('[aria-modal]'), 'aria-modal attribute added')
|
||||
assert.strictEqual($('#modal-test').attr('aria-modal'), 'true', 'correct aria-modal="true" added')
|
||||
$(this).bootstrapModal('hide')
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
assert.notOk($('#modal-test').is('[aria-modal]'), 'aria-modal attribute removed')
|
||||
assert.false($('#modal-test').is('[aria-modal]'), 'aria-modal attribute removed')
|
||||
done()
|
||||
})
|
||||
.bootstrapModal('show')
|
||||
@@ -329,12 +329,12 @@ $(function () {
|
||||
|
||||
$('<div id="modal-test"/>')
|
||||
.on('shown.bs.modal', function () {
|
||||
assert.ok($('#modal-test').is('[role]'), 'role attribute added')
|
||||
assert.true($('#modal-test').is('[role]'), 'role attribute added')
|
||||
assert.strictEqual($('#modal-test').attr('role'), 'dialog', 'correct role="dialog" added')
|
||||
$(this).bootstrapModal('hide')
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
assert.notOk($('#modal-test').is('[role]'), 'role attribute removed')
|
||||
assert.false($('#modal-test').is('[role]'), 'role attribute removed')
|
||||
done()
|
||||
})
|
||||
.bootstrapModal('show')
|
||||
@@ -350,13 +350,13 @@ $(function () {
|
||||
})
|
||||
.one('hidden.bs.modal', function () {
|
||||
// After one open-close cycle
|
||||
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
||||
assert.false($('#modal-test').is(':visible'), 'modal hidden')
|
||||
$(this)
|
||||
.one('shown.bs.modal', function () {
|
||||
$('#close').trigger('click')
|
||||
})
|
||||
.one('hidden.bs.modal', function () {
|
||||
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
||||
assert.false($('#modal-test').is(':visible'), 'modal hidden')
|
||||
done()
|
||||
})
|
||||
.bootstrapModal('show')
|
||||
@@ -373,7 +373,7 @@ $(function () {
|
||||
$('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div></div>')
|
||||
.on('hidden.bs.modal', function () {
|
||||
setTimeout(function () {
|
||||
assert.ok($(document.activeElement).is($toggleBtn), 'toggling element is once again focused')
|
||||
assert.true($(document.activeElement).is($toggleBtn), 'toggling element is once again focused')
|
||||
done()
|
||||
}, 0)
|
||||
})
|
||||
@@ -401,7 +401,7 @@ $(function () {
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
setTimeout(function () {
|
||||
assert.ok($(document.activeElement).is($otherBtn), 'focus returned to toggling element')
|
||||
assert.true($(document.activeElement).is($otherBtn), 'focus returned to toggling element')
|
||||
done()
|
||||
}, 0)
|
||||
})
|
||||
@@ -648,10 +648,10 @@ $(function () {
|
||||
|
||||
$('#test')
|
||||
.on('click.bs.modal.data-api', function (event) {
|
||||
assert.notOk(event.isDefaultPrevented(), 'navigating to href will happen')
|
||||
assert.false(event.isDefaultPrevented(), 'navigating to href will happen')
|
||||
|
||||
setTimeout(function () {
|
||||
assert.ok(event.isDefaultPrevented(), 'model shown instead of navigating to href')
|
||||
assert.true(event.isDefaultPrevented(), 'model shown instead of navigating to href')
|
||||
done()
|
||||
}, 1)
|
||||
})
|
||||
@@ -672,6 +672,7 @@ $(function () {
|
||||
}, 0)
|
||||
})
|
||||
|
||||
// eslint-disable-next-line qunit/resolve-async
|
||||
QUnit.test('should not execute js from target', function (assert) {
|
||||
assert.expect(0)
|
||||
var done = assert.async()
|
||||
@@ -742,7 +743,7 @@ $(function () {
|
||||
var spy = sinon.spy(Util, 'getTransitionDurationFromElement')
|
||||
|
||||
$modal.on('shown.bs.modal', function () {
|
||||
assert.ok(spy.returned(expectedTransitionDuration))
|
||||
assert.true(spy.returned(expectedTransitionDuration))
|
||||
$style.remove()
|
||||
spy.restore()
|
||||
done()
|
||||
@@ -777,11 +778,11 @@ $(function () {
|
||||
}
|
||||
})
|
||||
|
||||
assert.ok(typeof $(this).data('bs.modal') === 'undefined', 'modal data object was disposed')
|
||||
assert.strictEqual(typeof $(this).data('bs.modal'), 'undefined', 'modal data object was disposed')
|
||||
|
||||
assert.ok(spy.callCount === 4, '`jQuery.off` was called')
|
||||
assert.strictEqual(spy.callCount, 4, '`jQuery.off` was called')
|
||||
|
||||
assert.ok(modalDataApiEvent.length === 1, '`Event.CLICK_DATA_API` on `document` was not removed')
|
||||
assert.strictEqual(modalDataApiEvent.length, 1, '`Event.CLICK_DATA_API` on `document` was not removed')
|
||||
|
||||
$.fn.off.restore()
|
||||
done()
|
||||
@@ -849,7 +850,7 @@ $(function () {
|
||||
var spyDocOn = sinon.spy($(document), 'on')
|
||||
|
||||
$modal.one('shown.bs.modal', function () {
|
||||
assert.ok(spy.called, '_enforceFocus called')
|
||||
assert.true(spy.called, '_enforceFocus called')
|
||||
assert.ok(spyDocOff.withArgs('focusin.bs.modal'))
|
||||
assert.ok(spyDocOn.withArgs('focusin.bs.modal'))
|
||||
|
||||
@@ -859,7 +860,7 @@ $(function () {
|
||||
})
|
||||
|
||||
$(document).one('focusin', function () {
|
||||
assert.ok(spyFocus.called)
|
||||
assert.true(spyFocus.called)
|
||||
done()
|
||||
})
|
||||
|
||||
@@ -869,7 +870,7 @@ $(function () {
|
||||
})
|
||||
|
||||
QUnit.test('should scroll to top of the modal body if the modal has .modal-dialog-scrollable class', function (assert) {
|
||||
assert.expect(2)
|
||||
assert.expect(3)
|
||||
var done = assert.async()
|
||||
|
||||
var $modal = $([
|
||||
@@ -886,7 +887,8 @@ $(function () {
|
||||
|
||||
var $modalBody = $('.modal-body')
|
||||
$modalBody.scrollTop(100)
|
||||
assert.ok($modalBody.scrollTop() > 95 && $modalBody.scrollTop() <= 100)
|
||||
assert.true($modalBody.scrollTop() > 95)
|
||||
assert.true($modalBody.scrollTop() <= 100)
|
||||
|
||||
$modal.on('shown.bs.modal', function () {
|
||||
assert.strictEqual($modalBody.scrollTop(), 0, 'modal body scrollTop should be 0 when opened')
|
||||
@@ -925,12 +927,12 @@ $(function () {
|
||||
setTimeout(function () {
|
||||
var modal = $modal.data('bs.modal')
|
||||
|
||||
assert.strictEqual(modal._isShown, true)
|
||||
assert.true(modal._isShown)
|
||||
done()
|
||||
}, 10)
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
assert.strictEqual(true, false, 'should not hide the modal')
|
||||
assert.true(false, 'should not hide the modal')
|
||||
})
|
||||
.bootstrapModal({
|
||||
backdrop: 'static'
|
||||
@@ -950,7 +952,7 @@ $(function () {
|
||||
setTimeout(function () {
|
||||
var modal = $modal.data('bs.modal')
|
||||
|
||||
assert.strictEqual(modal._isShown, false)
|
||||
assert.false(modal._isShown)
|
||||
done()
|
||||
}, 10)
|
||||
})
|
||||
@@ -973,12 +975,12 @@ $(function () {
|
||||
setTimeout(function () {
|
||||
var modal = $modal.data('bs.modal')
|
||||
|
||||
assert.strictEqual(modal._isShown, true)
|
||||
assert.true(modal._isShown)
|
||||
done()
|
||||
}, 10)
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
assert.strictEqual(false, true, 'should not hide the modal')
|
||||
assert.false(true, 'should not hide the modal')
|
||||
})
|
||||
.bootstrapModal({
|
||||
keyboard: false
|
||||
@@ -1010,7 +1012,7 @@ $(function () {
|
||||
$modal.on('shown.bs.modal', function () {
|
||||
$modal.trigger('click')
|
||||
setTimeout(function () {
|
||||
assert.ok($modal.hasClass('modal-static'), 'has modal-static class')
|
||||
assert.true($modal.hasClass('modal-static'), 'has modal-static class')
|
||||
done()
|
||||
}, 0)
|
||||
})
|
||||
@@ -1032,7 +1034,7 @@ $(function () {
|
||||
$modal.on('shown.bs.modal', function () {
|
||||
$modal.trigger('click')
|
||||
setTimeout(function () {
|
||||
assert.notOk($modal.hasClass('modal-static'), 'should not have modal-static class')
|
||||
assert.false($modal.hasClass('modal-static'), 'should not have modal-static class')
|
||||
done()
|
||||
}, 0)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user