Skip to content

Commit dff0dc0

Browse files
authored
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
1 parent e31cf57 commit dff0dc0

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

tests/unit/dialog/core.js

+26-6
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,32 @@ QUnit.test( "focus tabbable", function( assert ) {
120120
function step1() {
121121
checkFocus( "<div><input><input></div>", options, function( done ) {
122122
var input = element.find( "input" ).last().trigger( "focus" ).trigger( "blur" );
123-
element.dialog( "instance" )._focusTabbable();
124-
setTimeout( function() {
125-
assert.equal( document.activeElement, input[ 0 ],
126-
"1. an element that was focused previously." );
127-
done();
128-
} );
123+
124+
// Support: IE 11+
125+
// In IE in jQuery 3.4+ a sequence:
126+
// $( inputNode ).trigger( "focus" ).trigger( "blur" ).trigger( "focus" )
127+
// doesn't end up with a focused input. See:
128+
// https://github.com/jquery/jquery/issues/4856
129+
// However, in this test we only want to check that the last focused
130+
// input receives the focus back when `_focusTabbable()` is called
131+
// which in reality doesn't happen so quickly so let's avoid the issue
132+
// by waiting a bit.
133+
if ( document.documentMode ) {
134+
setTimeout( function() {
135+
focusTabbableAndAssert();
136+
}, 500 );
137+
} else {
138+
focusTabbableAndAssert();
139+
}
140+
141+
function focusTabbableAndAssert() {
142+
element.dialog( "instance" )._focusTabbable();
143+
setTimeout( function() {
144+
assert.equal( document.activeElement, input[ 0 ],
145+
"1. an element that was focused previously." );
146+
done();
147+
} );
148+
}
129149
}, step2 );
130150
}
131151

0 commit comments

Comments
 (0)