Skip to content

Commit 33c80f3

Browse files
committed
Run focus test only if document has focus
(cherry picked from commit 0b9a182)
1 parent 9dadd68 commit 33c80f3

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

test/unit/event.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,35 +2567,35 @@ test( "make sure events cloned correctly", 18, function() {
25672567
clone.find("#check1").trigger("change"); // 0 events should fire
25682568
});
25692569

2570-
asyncTest( "Check order of focusin/focusout events", 2, function() {
2571-
var focus, blur,
2572-
input = jQuery("#name");
2570+
// This test fails in some browsers if document does not have focus
2571+
if ( !document.hasFocus || document.hasFocus && document.hasFocus() ) {
2572+
test( "Check order of focusin/focusout events", 2, function() {
2573+
var focus, blur,
2574+
input = jQuery( "#name" );
25732575

2574-
input.on("focus", function() {
2575-
focus = true;
2576+
input.on( "focus", function() {
2577+
focus = true;
25762578

2577-
}).on("focusin", function() {
2578-
ok( !focus, "Focusin event should fire before focus does" );
2579+
}).on( "focusin", function() {
2580+
ok( !focus, "Focusin event should fire before focus does" );
25792581

2580-
}).on("blur", function() {
2581-
blur = true;
2582+
}).on( "blur", function() {
2583+
blur = true;
25822584

2583-
}).on("focusout", function() {
2584-
ok( !blur, "Focusout event should fire before blur does" );
2585-
});
2585+
}).on( "focusout", function() {
2586+
ok( !blur, "Focusout event should fire before blur does" );
2587+
});
25862588

2587-
// gain focus
2588-
input.trigger("focus");
2589+
// gain focus
2590+
input.trigger( "focus" );
25892591

2590-
// then lose it
2591-
jQuery("#search").trigger("focus");
2592+
// then lose it
2593+
jQuery( "#search" ).trigger( "focus" );
25922594

2593-
// cleanup
2594-
setTimeout(function() {
2595+
// cleanup
25952596
input.off();
2596-
start();
2597-
}, 50 );
2598-
});
2597+
});
2598+
}
25992599

26002600
test( "String.prototype.namespace does not cause trigger() to throw (#13360)", function() {
26012601
expect( 1 );

0 commit comments

Comments
 (0)