Skip to content

Commit

Permalink
Fix dropdown unit test
Browse files Browse the repository at this point in the history
swap jQuery's `trigger(...)` with the more verbose native `dispatchEvent(...)`, as the former may not always behave/bubble correctly (observed while trying to write unit tests for keyboard handling of ARIA tab
navigation), which may lead to this test passing even though it fails in real usage.
  • Loading branch information
patrickhlauke committed Jul 13, 2019
1 parent 37ec7f6 commit 39fb607
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions js/tests/unit/dropdown.js
Expand Up @@ -88,10 +88,11 @@ $(function () {
$(dropdownHTML).appendTo('#qunit-fixture')
var $dropdown = $('#qunit-fixture').find('[data-toggle="dropdown"]').bootstrapDropdown()
var $button = $('button[data-toggle="dropdown"]')
$button[0].focus()
// Key escape
$button.trigger('focus').trigger($.Event('keydown', {
which: 27
}))
var keydown = new Event('keydown')
keydown.which = 27
$button[0].dispatchEvent(keydown)
assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is not shown after escape pressed')
done()
})
Expand Down

0 comments on commit 39fb607

Please sign in to comment.