diff --git a/js/tests/index.html b/js/tests/index.html index 77a97cc1f7..fab2ebc163 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -7,6 +7,46 @@ + diff --git a/js/tests/unit/alert.js b/js/tests/unit/alert.js index 0768a1e119..6be990a518 100644 --- a/js/tests/unit/alert.js +++ b/js/tests/unit/alert.js @@ -40,7 +40,7 @@ $(function () { + '' var $alert = $(alertHTML).bootstrapAlert() - $alert.find('.close').click() + $alert.find('.close').trigger('click') assert.strictEqual($alert.hasClass('in'), false, 'remove .in class on .close click') }) @@ -55,7 +55,7 @@ $(function () { assert.notEqual($('#qunit-fixture').find('.alert').length, 0, 'element added to dom') - $alert.find('.close').click() + $alert.find('.close').trigger('click') assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom') }) diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 7788addd13..02312ebaf5 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -106,7 +106,7 @@ $(function () { .append($inner) .appendTo('#qunit-fixture') assert.ok(!$btn.hasClass('active'), 'btn does not have active class') - $inner.click() + $inner.trigger('click') assert.ok($btn.hasClass('active'), 'btn has class active') }) @@ -126,7 +126,7 @@ $(function () { .append($inner) .appendTo('#qunit-fixture') assert.strictEqual($btn.attr('aria-pressed'), 'false', 'btn aria-pressed state is false') - $inner.click() + $inner.trigger('click') assert.strictEqual($btn.attr('aria-pressed'), 'true', 'btn aria-pressed state is true') }) @@ -139,7 +139,7 @@ $(function () { .append($btn.append($inner)) .appendTo('#qunit-fixture') assert.ok(!$btn.hasClass('active'), 'btn does not have active class') - $inner.click() + $inner.trigger('click') assert.ok($btn.hasClass('active'), 'btn has class active') }) @@ -165,13 +165,13 @@ $(function () { assert.ok($btn1.find('input').prop('checked'), 'btn1 is checked') assert.ok(!$btn2.hasClass('active'), 'btn2 does not have active class') assert.ok(!$btn2.find('input').prop('checked'), 'btn2 is not checked') - $btn2.find('input').click() + $btn2.find('input').trigger('click') assert.ok(!$btn1.hasClass('active'), 'btn1 does not have active class') assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is checked') assert.ok($btn2.hasClass('active'), 'btn2 has active class') assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked') - $btn2.find('input').click() // clicking an already checked radio should not un-check it + $btn2.find('input').trigger('click') // clicking an already checked radio should not un-check it assert.ok(!$btn1.hasClass('active'), 'btn1 does not have active class') assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is checked') assert.ok($btn2.hasClass('active'), 'btn2 has active class') diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 9c1c968e8a..39d2505980 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -336,19 +336,19 @@ $(function () { $carousel.attr('data-interval', 1814) $carousel.appendTo('body') - $('[data-slide]').first().click() + $('[data-slide]').first().trigger('click') assert.strictEqual($carousel.data('bs.carousel').options.interval, 1814) $carousel.remove() $carousel.appendTo('body').attr('data-modal', 'foobar') - $('[data-slide]').first().click() + $('[data-slide]').first().trigger('click') assert.strictEqual($carousel.data('bs.carousel').options.interval, 1814, 'even if there is an data-modal attribute set') $carousel.remove() $carousel.appendTo('body') - $('[data-slide]').first().click() + $('[data-slide]').first().trigger('click') $carousel.attr('data-interval', 1860) - $('[data-slide]').first().click() + $('[data-slide]').first().trigger('click') assert.strictEqual($carousel.data('bs.carousel').options.interval, 1814, 'attributes should be read only on initialization') $carousel.remove() diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index 8c01e57e86..5073bf1093 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -91,7 +91,7 @@ $(function () { done() }) - $target.click() + $target.trigger('click') }) QUnit.test('should add "collapsed" class to target when collapse is hidden', function (assert) { @@ -107,7 +107,7 @@ $(function () { done() }) - $target.click() + $target.trigger('click') }) QUnit.test('should remove "collapsed" class from all triggers targeting the collapse when the collapse is shown', function (assert) { @@ -125,7 +125,7 @@ $(function () { done() }) - $target.click() + $target.trigger('click') }) QUnit.test('should add "collapsed" class to all triggers targeting the collapse when the collapse is hidden', function (assert) { @@ -143,7 +143,7 @@ $(function () { done() }) - $target.click() + $target.trigger('click') }) QUnit.test('should not close a collapse when initialized with "show" option if already shown', function (assert) { @@ -235,7 +235,7 @@ $(function () { done() }) - $target3.click() + $target3.trigger('click') }) QUnit.test('should allow dots in data-parent', function (assert) { @@ -269,7 +269,7 @@ $(function () { done() }) - $target3.click() + $target3.trigger('click') }) QUnit.test('should set aria-expanded="true" on target when collapse is shown', function (assert) { @@ -285,7 +285,7 @@ $(function () { done() }) - $target.click() + $target.trigger('click') }) QUnit.test('should set aria-expanded="false" on target when collapse is hidden', function (assert) { @@ -301,7 +301,7 @@ $(function () { done() }) - $target.click() + $target.trigger('click') }) QUnit.test('should set aria-expanded="true" on all triggers targeting the collapse when the collapse is shown', function (assert) { @@ -319,7 +319,7 @@ $(function () { done() }) - $target.click() + $target.trigger('click') }) QUnit.test('should set aria-expanded="false" on all triggers targeting the collapse when the collapse is hidden', function (assert) { @@ -337,7 +337,7 @@ $(function () { done() }) - $target.click() + $target.trigger('click') }) QUnit.test('should change aria-expanded from active accordion target to "false" and set the newly active one to "true"', function (assert) { @@ -371,7 +371,7 @@ $(function () { done() }) - $target3.click() + $target3.trigger('click') }) QUnit.test('should not fire show event if show is prevented because other element is still transitioning', function (assert) { @@ -396,13 +396,13 @@ $(function () { var $target2 = $('').appendTo($groups.eq(1)) var $body2 = $('
').appendTo($groups.eq(1)) - $target2.click() + $target2.trigger('click') $body2 .toggleClass('in collapsing') .data('bs.collapse').transitioning = 1 - $target1.click() + $target1.trigger('click') setTimeout(function () { assert.ok(!showFired, 'show event did not fire') diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index a0c0c9fef1..40c428682f 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -45,7 +45,7 @@ $(function () { + '' + '' + '' - var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') }) @@ -66,7 +66,7 @@ $(function () { var $dropdown = $(dropdownHTML) .find('[data-toggle="dropdown"]') .bootstrapDropdown() - .click() + .trigger('click') assert.strictEqual($dropdown.attr('aria-expanded'), 'true', 'aria-expanded is set to string "true" on click') }) @@ -97,8 +97,8 @@ $(function () { done() }) - $dropdown.click() - $(document.body).click() + $dropdown.trigger('click') + $(document.body).trigger('click') }) QUnit.test('should not open dropdown if target is disabled via class', function (assert) { @@ -114,7 +114,7 @@ $(function () { + '' + '' + '' - var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') }) @@ -132,7 +132,7 @@ $(function () { + '' + '' + '' - var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') }) @@ -150,7 +150,7 @@ $(function () { + '' + '' + '' - var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') }) @@ -173,10 +173,10 @@ $(function () { .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') .bootstrapDropdown() - .click() + .trigger('click') assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') - $(document.body).click() + $(document.body).trigger('click') assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class removed') }) @@ -204,16 +204,16 @@ $(function () { assert.strictEqual($dropdowns.length, 2, 'two dropdowns') - $first.click() + $first.trigger('click') assert.strictEqual($first.parents('.open').length, 1, '"open" class added on click') assert.strictEqual($('#qunit-fixture .open').length, 1, 'only one dropdown is open') - $(document.body).click() + $(document.body).trigger('click') assert.strictEqual($('#qunit-fixture .open').length, 0, '"open" class removed') - $last.click() + $last.trigger('click') assert.strictEqual($last.parent('.open').length, 1, '"open" class added on click') assert.strictEqual($('#qunit-fixture .open').length, 1, 'only one dropdown is open') - $(document.body).click() + $(document.body).trigger('click') assert.strictEqual($('#qunit-fixture .open').length, 0, '"open" class removed') }) @@ -247,8 +247,8 @@ $(function () { done() }) - $dropdown.click() - $(document.body).click() + $dropdown.trigger('click') + $(document.body).trigger('click') }) @@ -282,8 +282,8 @@ $(function () { done() }) - $dropdown.click() - $(document.body).click() + $dropdown.trigger('click') + $(document.body).trigger('click') }) QUnit.test('should ignore keyboard events within s and