From cc49977038aa886ffa6c5905e2dba4c8cc3a6fd0 Mon Sep 17 00:00:00 2001 From: "Patrick H. Lauke" Date: Sun, 14 Jul 2019 10:24:27 +0100 Subject: [PATCH] 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. --- js/tests/unit/dropdown.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 04b506ff93..f4327959b7 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -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() })