]> source.dussan.org Git - jquery.git/commitdiff
Adding some more test coverage for .finish()
authorCorey Frang <gnarf@gnarf.net>
Tue, 8 Jan 2013 09:33:01 +0000 (03:33 -0600)
committerCorey Frang <gnarf@gnarf.net>
Tue, 8 Jan 2013 09:33:27 +0000 (03:33 -0600)
test/unit/effects.js

index 1e9093fb878341da3c32cbab523d0225f2562def..16b4c15e5ee5f179d3ab03b00b3914f4fbcf9b8c 100644 (file)
@@ -1891,7 +1891,7 @@ test( ".finish() completes all queued animations", function() {
                anim[ prop ] = value;
                // the delay shouldn't matter at all!
                div.css( prop, 1 ).animate( anim, function() {
-                       ok( true, "Called animation callback" );
+                       ok( true, "Called animation callback for " + prop );
                }).delay( 100 );
        });
        equal( div.queue().length, 8, "8 animations in the queue" );
@@ -1908,6 +1908,77 @@ test( ".finish() completes all queued animations", function() {
        jQuery.fx.tick();
 });
 
+test( ".finish( false ) - unqueued animations", function() {
+       var animations = {
+                       top: 100,
+                       left: 100,
+                       height: 100,
+                       width: 100
+               },
+               div = jQuery("<div>");
+
+       expect( 10 );
+
+       jQuery.each( animations, function( prop, value ) {
+               var anim = {};
+               anim[ prop ] = value;
+               div.css( prop, 1 ).animate( anim, {
+                       queue: false,
+                       complete: function() {
+                               ok( true, "Called animation callback for " + prop );
+                       }
+               });
+       });
+       equal( div.queue().length, 0, "0 animations in the queue" );
+       div.finish( false );
+       jQuery.each( animations, function( prop, value ) {
+               equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
+       });
+       equal( div.is(":animated"), false, ":animated doesn't match" );
+
+       // cleanup
+       div.remove();
+       // leaves a "shadow timer" which does nothing around, need to force a tick
+       jQuery.fx.tick();
+});
+
+test( ".finish( \"custom\" ) - custom queue animations", function() {
+       var animations = {
+                       top: 100,
+                       left: 100,
+                       height: 100,
+                       width: 100
+               },
+               div = jQuery("<div>");
+
+       expect( 11 );
+
+       jQuery.each( animations, function( prop, value ) {
+               var anim = {};
+               anim[ prop ] = value;
+               div.css( prop, 1 ).animate( anim, {
+                       queue: "custom",
+                       complete: function() {
+                               ok( true, "Called animation callback for " + prop );
+                       }
+               });
+       });
+       equal( div.queue( "custom" ).length, 4, "4 animations in the queue" );
+       // start the first animation
+       div.dequeue( "custom" );
+       equal( div.is(":animated"), true, ":animated matches" );
+       div.finish( "custom" );
+       jQuery.each( animations, function( prop, value ) {
+               equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
+       });
+       equal( div.is(":animated"), false, ":animated doesn't match" );
+
+       // cleanup
+       div.remove();
+       // leaves a "shadow timer" which does nothing around, need to force a tick
+       jQuery.fx.tick();
+});
+
 test( ".finish() calls finish of custom queue functions", function() {
        function queueTester( next ) {