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
This commit is contained in:
Michał Gołębiowski-Owczarek 2021-03-16 22:17:25 +01:00 committed by GitHub
parent e31cf579a0
commit dff0dc0d6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -120,12 +120,32 @@ QUnit.test( "focus tabbable", function( assert ) {
function step1() {
checkFocus( "<div><input><input></div>", options, function( done ) {
var input = element.find( "input" ).last().trigger( "focus" ).trigger( "blur" );
// 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 );
}