Skip to content

Commit

Permalink
Disable jQuery event aliases when running test suite
Browse files Browse the repository at this point in the history
To ensure that we don't accidentally use any of the aliases.
This should prevent any future regressions from #12761.
Also updates the test suite since it now can't use these aliases either.
  • Loading branch information
cvrebert committed Mar 9, 2015
1 parent 21d5637 commit 725c684
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 64 deletions.
40 changes: 40 additions & 0 deletions js/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,46 @@

<!-- jQuery -->
<script src="vendor/jquery.min.js"></script>
<script>
// Disable jQuery event aliases to ensure we don't accidentally use any of them
(function () {
var eventAliases = [
'blur',
'focus',
'focusin',
'focusout',
'load',
'resize',
'scroll',
'unload',
'click',
'dblclick',
'mousedown',
'mouseup',
'mousemove',
'mouseover',
'mouseout',
'mouseenter',
'mouseleave',
'change',
'select',
'submit',
'keydown',
'keypress',
'keyup',
'error',
'contextmenu',
'hover',
'bind',
'unbind',
'delegate',
'undelegate'
]
for (var i = 0; i < eventAliases.length; i++) {
$.fn[eventAliases[i]] = undefined
}
})()
</script>

<!-- QUnit -->
<link rel="stylesheet" href="vendor/qunit.css" media="screen">
Expand Down
4 changes: 2 additions & 2 deletions js/tests/unit/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $(function () {
+ '</div>'
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')
})
Expand All @@ -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')
})
Expand Down
10 changes: 5 additions & 5 deletions js/tests/unit/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

Expand All @@ -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')
})

Expand All @@ -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')
})

Expand All @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions js/tests/unit/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
26 changes: 13 additions & 13 deletions js/tests/unit/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -235,7 +235,7 @@ $(function () {
done()
})

$target3.click()
$target3.trigger('click')
})

QUnit.test('should allow dots in data-parent', function (assert) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -396,13 +396,13 @@ $(function () {
var $target2 = $('<a data-toggle="collapse" href="#body2" data-parent="#accordion"/>').appendTo($groups.eq(1))
var $body2 = $('<div id="body2" class="collapse"/>').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')
Expand Down
42 changes: 21 additions & 21 deletions js/tests/unit/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $(function () {
+ '</ul>'
+ '</li>'
+ '</ul>'
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')
})
Expand All @@ -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')
})
Expand Down Expand Up @@ -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) {
Expand All @@ -114,7 +114,7 @@ $(function () {
+ '</ul>'
+ '</li>'
+ '</ul>'
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')
})
Expand All @@ -132,7 +132,7 @@ $(function () {
+ '</ul>'
+ '</li>'
+ '</ul>'
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')
})
Expand All @@ -150,7 +150,7 @@ $(function () {
+ '</ul>'
+ '</li>'
+ '</ul>'
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')
})
Expand All @@ -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')
})

Expand Down Expand Up @@ -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')
})

Expand Down Expand Up @@ -247,8 +247,8 @@ $(function () {
done()
})

$dropdown.click()
$(document.body).click()
$dropdown.trigger('click')
$(document.body).trigger('click')
})


Expand Down Expand Up @@ -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 <input>s and <textarea>s', function (assert) {
Expand Down Expand Up @@ -316,16 +316,16 @@ $(function () {
.on('shown.bs.dropdown', function () {
assert.ok(true, 'shown was fired')

$input.focus().trigger($.Event('keydown', { which: 38 }))
$input.trigger('focus').trigger($.Event('keydown', { which: 38 }))
assert.ok($(document.activeElement).is($input), 'input still focused')

$textarea.focus().trigger($.Event('keydown', { which: 38 }))
$textarea.trigger('focus').trigger($.Event('keydown', { which: 38 }))
assert.ok($(document.activeElement).is($textarea), 'textarea still focused')

done()
})

$dropdown.click()
$dropdown.trigger('click')
})

QUnit.test('should skip disabled element when using keyboard navigation', function (assert) {
Expand All @@ -343,7 +343,7 @@ $(function () {
.appendTo('#qunit-fixture')
.find('[data-toggle="dropdown"]')
.bootstrapDropdown()
.click()
.trigger('click')

$dropdown.trigger($.Event('keydown', { which: 40 }))
$dropdown.trigger($.Event('keydown', { which: 40 }))
Expand Down
Loading

0 comments on commit 725c684

Please sign in to comment.