mirror of
https://github.com/tenrok/bootstrap.git
synced 2026-06-17 19:21:23 +03:00
JS unit tests: use QUnit.module() & QUnit.test() everywhere
[skip validator]
This commit is contained in:
+20
-20
@@ -1,13 +1,13 @@
|
||||
$(function () {
|
||||
'use strict';
|
||||
|
||||
module('modal plugin')
|
||||
QUnit.module('modal plugin')
|
||||
|
||||
test('should be defined on jquery object', function (assert) {
|
||||
QUnit.test('should be defined on jquery object', function (assert) {
|
||||
assert.ok($(document.body).modal, 'modal method is defined')
|
||||
})
|
||||
|
||||
module('modal', {
|
||||
QUnit.module('modal', {
|
||||
setup: function () {
|
||||
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
|
||||
$.fn.bootstrapModal = $.fn.modal.noConflict()
|
||||
@@ -18,22 +18,22 @@ $(function () {
|
||||
}
|
||||
})
|
||||
|
||||
test('should provide no conflict', function (assert) {
|
||||
QUnit.test('should provide no conflict', function (assert) {
|
||||
assert.strictEqual($.fn.modal, undefined, 'modal was set back to undefined (orig value)')
|
||||
})
|
||||
|
||||
test('should return jquery collection containing the element', function (assert) {
|
||||
QUnit.test('should return jquery collection containing the element', function (assert) {
|
||||
var $el = $('<div id="modal-test"/>')
|
||||
var $modal = $el.bootstrapModal()
|
||||
assert.ok($modal instanceof $, 'returns jquery collection')
|
||||
assert.strictEqual($modal[0], $el[0], 'collection contains element')
|
||||
})
|
||||
|
||||
test('should expose defaults var for settings', function (assert) {
|
||||
QUnit.test('should expose defaults var for settings', function (assert) {
|
||||
assert.ok($.fn.bootstrapModal.Constructor.DEFAULTS, 'default object exposed')
|
||||
})
|
||||
|
||||
test('should insert into dom when show method is called', function (assert) {
|
||||
QUnit.test('should insert into dom when show method is called', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
$('<div id="modal-test"/>')
|
||||
@@ -44,7 +44,7 @@ $(function () {
|
||||
.bootstrapModal('show')
|
||||
})
|
||||
|
||||
test('should fire show event', function (assert) {
|
||||
QUnit.test('should fire show event', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
$('<div id="modal-test"/>')
|
||||
@@ -55,7 +55,7 @@ $(function () {
|
||||
.bootstrapModal('show')
|
||||
})
|
||||
|
||||
test('should not fire shown when show was prevented', function (assert) {
|
||||
QUnit.test('should not fire shown when show was prevented', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
$('<div id="modal-test"/>')
|
||||
@@ -70,7 +70,7 @@ $(function () {
|
||||
.bootstrapModal('show')
|
||||
})
|
||||
|
||||
test('should hide modal when hide is called', function (assert) {
|
||||
QUnit.test('should hide modal when hide is called', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
$('<div id="modal-test"/>')
|
||||
@@ -86,7 +86,7 @@ $(function () {
|
||||
.bootstrapModal('show')
|
||||
})
|
||||
|
||||
test('should toggle when toggle is called', function (assert) {
|
||||
QUnit.test('should toggle when toggle is called', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
$('<div id="modal-test"/>')
|
||||
@@ -102,7 +102,7 @@ $(function () {
|
||||
.bootstrapModal('toggle')
|
||||
})
|
||||
|
||||
test('should remove from dom when click [data-dismiss="modal"]', function (assert) {
|
||||
QUnit.test('should remove from dom when click [data-dismiss="modal"]', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
$('<div id="modal-test"><span class="close" data-dismiss="modal"/></div>')
|
||||
@@ -118,7 +118,7 @@ $(function () {
|
||||
.bootstrapModal('toggle')
|
||||
})
|
||||
|
||||
test('should allow modal close with "backdrop:false"', function (assert) {
|
||||
QUnit.test('should allow modal close with "backdrop:false"', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
$('<div id="modal-test" data-backdrop="false"/>')
|
||||
@@ -133,7 +133,7 @@ $(function () {
|
||||
.bootstrapModal('show')
|
||||
})
|
||||
|
||||
test('should close modal when clicking outside of modal-content', function (assert) {
|
||||
QUnit.test('should close modal when clicking outside of modal-content', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
$('<div id="modal-test"><div class="contents"/></div>')
|
||||
@@ -150,7 +150,7 @@ $(function () {
|
||||
.bootstrapModal('show')
|
||||
})
|
||||
|
||||
test('should close modal when escape key is pressed via keydown', function (assert) {
|
||||
QUnit.test('should close modal when escape key is pressed via keydown', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
var div = $('<div id="modal-test"/>')
|
||||
@@ -169,7 +169,7 @@ $(function () {
|
||||
.bootstrapModal('show')
|
||||
})
|
||||
|
||||
test('should not close modal when escape key is pressed via keyup', function (assert) {
|
||||
QUnit.test('should not close modal when escape key is pressed via keyup', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
var div = $('<div id="modal-test"/>')
|
||||
@@ -188,7 +188,7 @@ $(function () {
|
||||
.bootstrapModal('show')
|
||||
})
|
||||
|
||||
test('should trigger hide event once when clicking outside of modal-content', function (assert) {
|
||||
QUnit.test('should trigger hide event once when clicking outside of modal-content', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
var triggered
|
||||
@@ -206,7 +206,7 @@ $(function () {
|
||||
.bootstrapModal('show')
|
||||
})
|
||||
|
||||
test('should close reopened modal with [data-dismiss="modal"] click', function (assert) {
|
||||
QUnit.test('should close reopened modal with [data-dismiss="modal"] click', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
$('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div></div>')
|
||||
@@ -229,7 +229,7 @@ $(function () {
|
||||
.bootstrapModal('show')
|
||||
})
|
||||
|
||||
test('should restore focus to toggling element when modal is hidden after having been opened via data-api', function (assert) {
|
||||
QUnit.test('should restore focus to toggling element when modal is hidden after having been opened via data-api', function (assert) {
|
||||
var done = assert.async()
|
||||
|
||||
var $toggleBtn = $('<button data-toggle="modal" data-target="#modal-test"/>').appendTo('#qunit-fixture')
|
||||
@@ -249,7 +249,7 @@ $(function () {
|
||||
$toggleBtn.click()
|
||||
})
|
||||
|
||||
test('should not restore focus to toggling element if the associated show event gets prevented', function (assert) {
|
||||
QUnit.test('should not restore focus to toggling element if the associated show event gets prevented', function (assert) {
|
||||
var done = assert.async()
|
||||
var $toggleBtn = $('<button data-toggle="modal" data-target="#modal-test"/>').appendTo('#qunit-fixture')
|
||||
var $otherBtn = $('<button id="other-btn"/>').appendTo('#qunit-fixture')
|
||||
|
||||
Reference in New Issue
Block a user