Fix dropdown unit test (#29037)

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.
This commit is contained in:
Patrick H. Lauke 2019-07-14 10:24:27 +01:00 committed by XhmikosR
parent cef69b9a65
commit cc49977038
1 changed files with 4 additions and 3 deletions

View File

@ -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()
})