From dff0dc0d6af9834f03902fe260b51a15de3ab498 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Tue, 16 Mar 2021 22:17:25 +0100 Subject: [PATCH] Tests: Fix the "dialog: core: focus tabbable" test in IE In IE in jQuery 3.4+ a sequence: ```js $( inputNode ).trigger( "focus" ).trigger( "blur" ).trigger( "focus" ); ``` doesn't end up with a focused input. However, in this test we only want to check that the last focused input receives the focus back when `_focusTabbable()` is called which in reality doesn't happen so quickly so let's avoid the issue by waiting a bit. Ref jquery/jquery#4856 Closes gh-1951 --- tests/unit/dialog/core.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/tests/unit/dialog/core.js b/tests/unit/dialog/core.js index 169734f1c..171d2789e 100644 --- a/tests/unit/dialog/core.js +++ b/tests/unit/dialog/core.js @@ -120,12 +120,32 @@ QUnit.test( "focus tabbable", function( assert ) { function step1() { checkFocus( "
", options, function( done ) { var input = element.find( "input" ).last().trigger( "focus" ).trigger( "blur" ); - element.dialog( "instance" )._focusTabbable(); - setTimeout( function() { - assert.equal( document.activeElement, input[ 0 ], - "1. an element that was focused previously." ); - done(); - } ); + + // Support: IE 11+ + // In IE in jQuery 3.4+ a sequence: + // $( inputNode ).trigger( "focus" ).trigger( "blur" ).trigger( "focus" ) + // doesn't end up with a focused input. See: + // https://github.com/jquery/jquery/issues/4856 + // However, in this test we only want to check that the last focused + // input receives the focus back when `_focusTabbable()` is called + // which in reality doesn't happen so quickly so let's avoid the issue + // by waiting a bit. + if ( document.documentMode ) { + setTimeout( function() { + focusTabbableAndAssert(); + }, 500 ); + } else { + focusTabbableAndAssert(); + } + + function focusTabbableAndAssert() { + element.dialog( "instance" )._focusTabbable(); + setTimeout( function() { + assert.equal( document.activeElement, input[ 0 ], + "1. an element that was focused previously." ); + done(); + } ); + } }, step2 ); } -- 2.39.5