From: Patrick H. Lauke Date: Sun, 14 Jul 2019 09:24:27 +0000 (+0100) Subject: Fix dropdown unit test (#29037) X-Git-Tag: v5.0.0-alpha1~1028 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc49977038aa886ffa6c5905e2dba4c8cc3a6fd0;p=thirdparty%2Fbootstrap.git 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. --- 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() })