]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Fix dropdown unit test (#29037)
authorPatrick H. Lauke <redux@splintered.co.uk>
Sun, 14 Jul 2019 09:24:27 +0000 (10:24 +0100)
committerXhmikosR <xhmikosr@gmail.com>
Sun, 14 Jul 2019 09:24:27 +0000 (12:24 +0300)
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

index 04b506ff93ef17a18699afc7f5fa9a485cd877ee..f4327959b7d49b6e4b361346f623bf7410884918 100644 (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()
   })