Skip to content

Commit 31a19a8

Browse files
committed
Rewriting unit test to be less sticky based on time issues
1 parent 74490f8 commit 31a19a8

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
@@ -603,28 +603,37 @@ test("stop()", function() {
603603
});
604604

605605
test("stop() - several in queue", function() {
606-
expect(3);
607-
stop();
606+
expect( 5 );
608607

609-
var $foo = jQuery("#foo");
610-
var w = 0;
611-
$foo.hide( 1000 ).css( "width", 200 ).css("width");
608+
var nw, time,
609+
$foo = jQuery( "#foo" ),
610+
w = 0;
612611

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

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

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

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

0 commit comments

Comments
 (0)