Skip to content

Commit 08894dc

Browse files
committed
Rewriting unit test to be less sticky based on time issues
(cherry picked from commit 31a19a8)
1 parent 986d0f5 commit 08894dc

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

test/unit/effects.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -597,28 +597,37 @@ test("stop()", function() {
597597
});
598598

599599
test("stop() - several in queue", function() {
600-
expect(3);
601-
stop();
600+
expect( 5 );
602601

603-
var $foo = jQuery("#foo");
604-
var w = 0;
605-
$foo.hide( 1000 ).css( "width", 200 ).css("width");
602+
var nw, time,
603+
$foo = jQuery( "#foo" ),
604+
w = 0;
606605

607-
$foo.animate({ "width": "show" }, 1500);
608-
$foo.animate({ "width": "hide" }, 1000);
609-
$foo.animate({ "width": "show" }, 1000);
610-
setTimeout(function(){
611-
equal( $foo.queue().length, 3, "All 3 still in the queue" );
612-
var nw = $foo.css("width");
613-
notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px");
614-
$foo.stop();
606+
// default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms
607+
$foo.hide().css( "width", 800 );
615608

616-
nw = $foo.css("width");
617-
notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px");
609+
$foo.animate({ "width": "show" }, 400, "linear");
610+
$foo.animate({ "width": "hide" });
611+
$foo.animate({ "width": "show" });
618612

619-
$foo.stop(true);
620-
start();
621-
}, 200);
613+
// could be replaced by something nicer using sinon.
614+
time = jQuery.now();
615+
while( time === jQuery.now() ) {}
616+
617+
jQuery.fx.tick();
618+
equal( $foo.queue().length, 3, "3 in the queue" );
619+
620+
nw = $foo.css( "width" );
621+
notEqual( parseFloat( nw ), 1, "An animation occurred " + nw );
622+
$foo.stop();
623+
624+
equal( $foo.queue().length, 2, "2 in the queue" );
625+
nw = $foo.css( "width" );
626+
notEqual( parseFloat( nw ), 1, "Stop didn't reset the animation " + nw );
627+
628+
$foo.stop( true );
629+
630+
equal( $foo.queue().length, 0, "0 in the queue" );
622631
});
623632

624633
test("stop(clearQueue)", function() {

0 commit comments

Comments
 (0)