From: Corey Frang Date: Thu, 8 Nov 2012 03:11:16 +0000 (-0600) Subject: Rewriting unit test to be less sticky based on time issues X-Git-Tag: 1.8.3~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=08894dccab5f3e37152b1f2c4e83acf561120a33;p=jquery.git Rewriting unit test to be less sticky based on time issues (cherry picked from commit 31a19a80bf216f8bf67e8be19d61355b310adfac) --- diff --git a/test/unit/effects.js b/test/unit/effects.js index aca24b8ab..1db4655d5 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -597,28 +597,37 @@ test("stop()", function() { }); test("stop() - several in queue", function() { - expect(3); - stop(); + expect( 5 ); - var $foo = jQuery("#foo"); - var w = 0; - $foo.hide( 1000 ).css( "width", 200 ).css("width"); + var nw, time, + $foo = jQuery( "#foo" ), + w = 0; - $foo.animate({ "width": "show" }, 1500); - $foo.animate({ "width": "hide" }, 1000); - $foo.animate({ "width": "show" }, 1000); - setTimeout(function(){ - equal( $foo.queue().length, 3, "All 3 still in the queue" ); - var nw = $foo.css("width"); - notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px"); - $foo.stop(); + // default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms + $foo.hide().css( "width", 800 ); - nw = $foo.css("width"); - notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px"); + $foo.animate({ "width": "show" }, 400, "linear"); + $foo.animate({ "width": "hide" }); + $foo.animate({ "width": "show" }); - $foo.stop(true); - start(); - }, 200); + // could be replaced by something nicer using sinon. + time = jQuery.now(); + while( time === jQuery.now() ) {} + + jQuery.fx.tick(); + equal( $foo.queue().length, 3, "3 in the queue" ); + + nw = $foo.css( "width" ); + notEqual( parseFloat( nw ), 1, "An animation occurred " + nw ); + $foo.stop(); + + equal( $foo.queue().length, 2, "2 in the queue" ); + nw = $foo.css( "width" ); + notEqual( parseFloat( nw ), 1, "Stop didn't reset the animation " + nw ); + + $foo.stop( true ); + + equal( $foo.queue().length, 0, "0 in the queue" ); }); test("stop(clearQueue)", function() {