3 // Can't test what ain't there
8 var off = jQuery.fx.off;
12 this.clock = sinon.useFakeTimers( 505877050 );
13 this._oldInterval = jQuery.fx.interval;
14 jQuery.fx.interval = 10;
15 jQuery.now = Date.now;
17 teardown: function() {
19 jQuery.now = Date.now;
21 jQuery.fx.interval = this._oldInterval;
23 return moduleTeardown.apply( this, arguments );
27 test("sanity check", function() {
29 ok( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
32 test("show() basic", 2, function() {
34 hiddendiv = jQuery("div.hidden");
36 hiddendiv.hide().show();
38 equal( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
40 div = jQuery("<div>").hide().appendTo("#qunit-fixture").show();
42 equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
44 // Clean up the detached node
47 QUnit.expectJqData(hiddendiv, "olddisplay");
50 test("show()", 27, function () {
51 var div, speeds, old, test,
52 hiddendiv = jQuery("div.hidden");
54 equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
56 hiddendiv.css("display", "block");
57 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
60 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
62 hiddendiv.css("display","");
64 div = jQuery("#fx-queue div").slice(0, 4);
65 div.show().each(function() {
66 notEqual(this.style.display, "none", "don't change any <div> with display block");
71 "undefined speed": undefined,
75 jQuery.each(speeds, function(name, speed) {
77 div.hide().show(speed).each(function() {
78 if ( this.style.display === "none" ) {
82 ok( pass, "Show with " + name);
85 jQuery.each(speeds, function(name, speed) {
87 div.hide().show(speed, function() {
90 ok( pass, "Show with " + name + " does not call animate callback" );
93 // Tolerate data from show()/hide()
94 QUnit.expectJqData(div, "olddisplay");
96 // #show-tests * is set display: none in CSS
97 jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
99 old = jQuery("#test-table").show().css("display") !== "table";
100 jQuery("#test-table").remove();
109 "table" : old ? "block" : "table",
110 "thead" : old ? "block" : "table-header-group",
111 "tbody" : old ? "block" : "table-row-group",
112 "tr" : old ? "block" : "table-row",
113 "th" : old ? "block" : "table-cell",
114 "td" : old ? "block" : "table-cell",
116 "li" : old ? "block" : "list-item"
119 jQuery.each(test, function(selector, expected) {
120 var elem = jQuery(selector, "#show-tests").show();
121 equal( elem.css("display"), expected, "Show using correct display type for " + selector );
124 jQuery("#show-tests").remove();
126 // Make sure that showing or hiding a text node doesn't cause an error
127 jQuery("<div>test</div> text <span>test</span>").show().remove();
128 jQuery("<div>test</div> text <span>test</span>").hide().remove();
131 test("show(Number) - other displays", function() {
134 // #show-tests * is set display: none in CSS
135 jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
138 old = jQuery("#test-table").show().css("display") !== "table";
139 jQuery("#test-table").remove();
141 // Note: inline elements are expected to be inline-block
142 // because we're showing width/height
143 // Can't animate width/height inline
148 "a" : "inline-block",
149 "code" : "inline-block",
151 "span" : "inline-block",
152 "table" : old ? "block" : "table",
153 "thead" : old ? "block" : "table-header-group",
154 "tbody" : old ? "block" : "table-row-group",
155 "tr" : old ? "block" : "table-row",
156 "th" : old ? "block" : "table-cell",
157 "td" : old ? "block" : "table-cell",
159 "li" : old ? "block" : "list-item"
162 jQuery.each(test, function(selector, expected) {
163 var elem = jQuery(selector, "#show-tests").show(1, function() {
164 equal( elem.css("display"), expected, "Show using correct display type for " + selector );
167 this.clock.tick( 10 );
169 jQuery("#show-tests").remove();
173 test("Persist correct display value", function() {
176 // #show-tests * is set display: none in CSS
177 jQuery("#qunit-fixture").append("<div id='show-tests'><span style='position:absolute;'>foo</span></div>");
179 var $span = jQuery("#show-tests span"),
180 displayNone = $span.css("display"),
186 display = $span.css("display");
190 $span.fadeIn(100, function() {
191 equal($span.css("display"), display, "Expecting display: " + display);
192 $span.fadeOut(100, function () {
193 equal($span.css("display"), displayNone, "Expecting display: " + displayNone);
194 $span.fadeIn(100, function() {
195 equal($span.css("display"), display, "Expecting display: " + display);
202 QUnit.expectJqData($span, "olddisplay");
205 test("animate(Hash, Object, Function)", function() {
207 var hash = {opacity: "show"},
208 hashCopy = jQuery.extend({}, hash);
209 jQuery("#foo").animate(hash, 0, function() {
210 equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
214 test("animate relative values", function() {
218 bases = [ "%", "px", "em" ],
219 adjustments = [ "px", "em" ],
220 container = jQuery("<div></div>")
221 .css({ position: "absolute", height: "50em", width: "50em" }),
222 animations = bases.length * adjustments.length;
224 expect( 2 * animations );
226 jQuery.each( bases, function( _, baseUnit ) {
227 jQuery.each( adjustments, function( _, adjustUnit ) {
228 var base = value + baseUnit,
229 adjust = { height: "+=2" + adjustUnit, width: "-=2" + adjustUnit },
230 elem = jQuery("<div></div>")
231 .appendTo( container.clone().appendTo("#qunit-fixture") )
233 position: "absolute",
235 width: value + adjustUnit
237 baseScale = elem[ 0 ].offsetHeight / value,
238 adjustScale = elem[ 0 ].offsetWidth / value;
240 elem.css( "width", base ).animate( adjust, 100, function() {
241 equal( this.offsetHeight, value * baseScale + 2 * adjustScale,
242 baseUnit + "+=" + adjustUnit );
243 equal( this.offsetWidth, value * baseScale - 2 * adjustScale,
244 baseUnit + "-=" + adjustUnit );
253 test("animate negative height", function() {
255 jQuery("#foo").animate({ height: -100 }, 100, function() {
256 equal( this.offsetHeight, 0, "Verify height." );
258 this.clock.tick( 100 );
261 test("animate negative margin", function() {
263 jQuery("#foo").animate({ "marginTop": -100 }, 100, function() {
264 equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
266 this.clock.tick( 100 );
269 test("animate negative margin with px", function() {
271 jQuery("#foo").animate({ marginTop: "-100px" }, 100, function() {
272 equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
274 this.clock.tick( 100 );
277 test("animate negative padding", function() {
279 jQuery("#foo").animate({ "paddingBottom": -100 }, 100, function() {
280 equal( jQuery(this).css("paddingBottom"), "0px", "Verify paddingBottom." );
282 this.clock.tick( 100 );
285 test("animate block as inline width/height", function() {
289 jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
290 equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
291 equal( this.offsetWidth, 42, "width was animated" );
292 equal( this.offsetHeight, 42, "height was animated" );
294 this.clock.tick( 100 );
297 test("animate native inline width/height", function() {
300 jQuery("#foo").css({ display: "", width: "", height: "" })
301 .append("<span>text</span>")
303 .animate({ width: 42, height: 42 }, 100, function() {
304 equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
305 equal( this.offsetWidth, 42, "width was animated" );
306 equal( this.offsetHeight, 42, "height was animated" );
308 this.clock.tick( 100 );
311 test( "animate block width/height", function() {
314 jQuery("<div>").appendTo("#qunit-fixture").css({
325 if ( jQuery( this ).width() > 42 ) {
326 ok( false, "width was incorrectly augmented during animation" );
329 complete: function() {
330 equal( jQuery( this ).css("display"), "block", "inline-block was not set on block element when animating width/height" );
331 equal( jQuery( this ).width(), 42, "width was animated" );
332 equal( jQuery( this ).height(), 42, "height was animated" );
335 this.clock.tick( 100 );
338 test("animate table width/height", function() {
341 var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
343 jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
344 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
346 this.clock.tick( 100 );
349 test("animate table-row width/height", function() {
351 var tr = jQuery( "#table" )
352 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
353 .html( "<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>" )
356 tr.animate({ width: 10, height: 10 }, 100, function() {
357 equal( jQuery( this ).css( "display" ), "table-row", "display mode is correct" );
358 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
359 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
361 this.clock.tick( 100 );
364 test("animate table-cell width/height", function() {
365 // Support: Chrome 31.
366 // Chrome 31 reports incorrect offsetWidth on a table cell with fixed width.
367 // This is fixed in Chrome 32 so let's just skip the failing test in Chrome 31.
368 // See https://code.google.com/p/chromium/issues/detail?id=290399
370 chrome31 = navigator.userAgent.indexOf( " Chrome/31." ) !== -1;
378 td = jQuery( "#table" )
379 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
380 .html( "<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>" )
383 td.animate({ width: 10, height: 10 }, 100, function() {
384 equal( jQuery( this ).css( "display" ), "table-cell", "display mode is correct" );
386 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
388 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
390 this.clock.tick( 100 );
393 test("animate percentage(%) on width/height", function() {
396 var $div = jQuery("<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>")
397 .appendTo("#qunit-fixture").children("div");
399 $div.animate({ width: "25%", height: "25%" }, 13, function() {
400 var $this = jQuery(this);
401 equal( $this.css("width"), "15px", "Width was animated to 15px rather than 25px");
402 equal( $this.css("height"), "15px", "Height was animated to 15px rather than 25px");
404 this.clock.tick( 20 );
407 test("animate resets overflow-x and overflow-y when finished", function() {
410 .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
411 .animate({ width: 42, height: 42 }, 100, function() {
412 equal( this.style.overflowX, "visible", "overflow-x is visible" );
413 equal( this.style.overflowY, "auto", "overflow-y is auto" );
415 this.clock.tick( 100 );
418 /* // This test ends up being flaky depending upon the CPU load
419 test("animate option (queue === false)", function () {
425 var $foo = jQuery("#foo");
426 $foo.animate({width:"100px"}, 3000, function () {
427 // should finish after unqueued animation so second
429 deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" );
432 $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
433 // short duration and out of queue so should finish first
439 test( "animate option { queue: false }", function() {
441 var foo = jQuery( "#foo" );
448 complete: function() {
449 ok( true, "Animation Completed" );
452 this.clock.tick( 10 );
454 equal( foo.queue().length, 0, "Queue is empty" );
457 test( "animate option { queue: true }", function() {
459 var foo = jQuery( "#foo" );
466 complete: function() {
467 ok( true, "Animation Completed" );
471 notEqual( foo.queue().length, 0, "Default queue is not empty" );
473 //clear out existing timers before next test
474 this.clock.tick( 10 );
477 test( "animate option { queue: 'name' }", function() {
479 var foo = jQuery( "#foo" ),
480 origWidth = parseFloat( foo.css("width") ),
483 foo.animate( { width: origWidth + 100 }, {
486 complete: function() {
488 // second callback function
490 equal( parseFloat( foo.css("width") ), origWidth + 100, "Animation ended" );
491 equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
493 }).queue( "name", function() {
495 // last callback function
496 deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
500 // this is the first callback function that should be called
502 equal( parseFloat( foo.css("width") ), origWidth, "Animation does not start on its own." );
503 equal( foo.queue("name").length, 2, "Queue length of 'name' queue" );
505 foo.dequeue( "name" );
506 this.clock.tick( 10 );
510 test("animate with no properties", function() {
514 divs = jQuery("div"),
517 divs.animate({}, function(){
521 equal( divs.length, count, "Make sure that callback is called for each element in the set." );
524 foo = jQuery("#foo");
527 foo.animate({top: 10}, 100, function(){
528 ok( true, "Animation was properly dequeued." );
530 this.clock.tick( 100 );
533 test("animate duration 0", function() {
538 $elems = jQuery([{ a:0 },{ a:0 }]),
541 equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
543 $elems.eq(0).animate( {a:1}, 0, function(){
544 ok( true, "Animate a simple property." );
548 // Failed until [6115]
549 equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
551 equal( counter, 1, "One synchronic animations" );
553 $elems.animate( { a:2 }, 0, function(){
554 ok( true, "Animate a second simple property." );
558 equal( counter, 3, "Multiple synchronic animations" );
560 $elems.eq(0).animate( {a:3}, 0, function(){
561 ok( true, "Animate a third simple property." );
564 $elems.eq(1).animate( {a:3}, 200, function(){
566 // Failed until [6115]
567 equal( counter, 5, "One synchronic and one asynchronic" );
569 this.clock.tick( 200 );
571 $elem = jQuery("<div />");
572 $elem.show(0, function(){
573 ok(true, "Show callback with no duration");
575 $elem.hide(0, function(){
576 ok(true, "Hide callback with no duration");
579 // manually clean up detached elements
583 test("animate hyphenated properties", function() {
587 .css("font-size", 10)
588 .animate({"font-size": 20}, 200, function() {
589 equal( this.style.fontSize, "20px", "The font-size property was animated." );
591 // FIXME why is this double only when run with other tests
592 this.clock.tick( 400 );
596 test("animate non-element", function() {
599 var obj = { test: 0 };
601 jQuery(obj).animate({test: 200}, 200, function(){
602 equal( obj.test, 200, "The custom property should be modified." );
604 this.clock.tick( 200 );
607 test("stop()", function() {
611 $foo = jQuery("#foo"),
615 $foo.hide().css( "width", 200 )
616 .animate( { "width": "show" }, 1500 );
618 this.clock.tick( 100 );
619 nw = $foo.css("width");
620 notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px" );
623 nw = $foo.css("width");
624 notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px" );
626 this.clock.tick( 100 );
629 $foo.removeData(undefined, true);
630 equal( nw, $foo.css("width"), "The animation didn't continue" );
632 $one = jQuery("#fadein");
633 $two = jQuery("#show");
634 $one.fadeTo(100, 0, function() {
637 this.clock.tick( 100 );
638 $two.fadeTo(100, 0, function() {
639 equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" );
641 $one.add( $two ).css("opacity", "");
643 this.clock.tick( 100 );
646 test("stop() - several in queue", function() {
649 var nw, $foo = jQuery( "#foo" );
651 // default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms
652 $foo.hide().css( "width", 800 );
654 $foo.animate({ "width": "show" }, 400, "linear");
655 $foo.animate({ "width": "hide" });
656 $foo.animate({ "width": "show" });
658 this.clock.tick( 1 );
661 equal( $foo.queue().length, 3, "3 in the queue" );
663 nw = $foo.css( "width" );
664 notEqual( parseFloat( nw ), 1, "An animation occurred " + nw );
667 equal( $foo.queue().length, 2, "2 in the queue" );
668 nw = $foo.css( "width" );
669 notEqual( parseFloat( nw ), 1, "Stop didn't reset the animation " + nw );
673 equal( $foo.queue().length, 0, "0 in the queue" );
676 test("stop(clearQueue)", function() {
679 var $foo = jQuery("#foo"),
682 $foo.hide().css( "width", 200 ).css("width");
684 $foo.animate({ "width": "show" }, 1000);
685 $foo.animate({ "width": "hide" }, 1000);
686 $foo.animate({ "width": "show" }, 1000);
687 this.clock.tick( 100 );
688 nw = $foo.css("width");
689 ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
692 nw = $foo.css("width");
693 ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px");
695 equal( $foo.queue().length, 0, "The animation queue was cleared" );
696 this.clock.tick( 100 );
697 equal( nw, $foo.css("width"), "The animation didn't continue" );
700 test("stop(clearQueue, gotoEnd)", function() {
703 var $foo = jQuery("#foo"),
706 $foo.hide().css( "width", 200 ).css("width");
708 $foo.animate({ width: "show" }, 1000);
709 $foo.animate({ width: "hide" }, 1000);
710 $foo.animate({ width: "show" }, 1000);
711 $foo.animate({ width: "hide" }, 1000);
712 this.clock.tick( 100 );
713 nw = $foo.css("width");
714 ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
715 $foo.stop(false, true);
717 nw = $foo.css("width");
718 // Disabled, being flaky
719 //equal( nw, 1, "Stop() reset the animation" );
721 this.clock.tick( 100 );
722 // Disabled, being flaky
723 //equal( $foo.queue().length, 2, "The next animation continued" );
727 test( "stop( queue, ..., ... ) - Stop single queues", function() {
730 foo = jQuery("#foo").css({ width: 200, height: 200 });
736 complete: function() {
737 equal( parseFloat( foo.css("width") ), 400, "Animation completed for standard queue" );
738 equal( parseFloat( foo.css("height") ), saved, "Height was not changed after the second stop");
747 }).dequeue("height").stop( "height", false, true );
749 equal( parseFloat( foo.css("height") ), 400, "Height was stopped with gotoEnd" );
756 }).dequeue( "height" ).stop( "height", false, false );
757 saved = parseFloat( foo.css("height") );
758 this.clock.tick( 500 );
761 test("toggle()", function() {
763 var x = jQuery("#foo");
764 ok( x.is(":visible"), "is visible" );
766 ok( x.is(":hidden"), "is hidden" );
768 ok( x.is(":visible"), "is visible again" );
771 ok( x.is(":visible"), "is visible" );
773 ok( x.is(":hidden"), "is hidden" );
775 ok( x.is(":visible"), "is visible again" );
778 test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() {
779 var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
781 border: "5px solid black",
783 marginBottom: "-11000px"
787 ( new jQuery.fx( div, {}, "color" ) ).cur(),
788 jQuery.css( div, "color" ),
789 "Return the same value as jQuery.css for complex properties (bug #7912)"
793 ( new jQuery.fx( div, {}, "borderLeftWidth" ) ).cur(),
795 "Return simple values parsed as Float"
798 // backgroundPosition actually returns 0% 0% in most browser
799 // this fakes a "" return
800 // hook now gets called twice because Tween will grab the current
801 // value as it is being newed
802 jQuery.cssHooks.backgroundPosition = {
804 ok( true, "hook used" );
810 ( new jQuery.fx( div, {}, "backgroundPosition" ) ).cur(),
812 "Return 0 when jQuery.css returns an empty string"
815 delete jQuery.cssHooks.backgroundPosition;
818 ( new jQuery.fx( div, {}, "left" ) ).cur(),
820 "Return 0 when jQuery.css returns 'auto'"
824 ( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
826 "support negative values < -10000 (bug #7193)"
829 jQuery( div ).remove();
832 test("Overflow and Display", function() {
836 testClass = jQuery.makeTest("Overflow and Display")
837 .addClass("overflow inline"),
838 testStyle = jQuery.makeTest("Overflow and Display (inline style)")
839 .css({ overflow: "visible", display: "inline" }),
841 equal( jQuery.css( this, "overflow" ), "visible", "Overflow should be 'visible'" );
842 equal( jQuery.css( this, "display" ), "inline", "Display should be 'inline'" );
845 testClass.add( testStyle )
846 .addClass("widewidth")
847 .text("Some sample text.")
848 .before("text before")
850 .animate({ opacity: 0.5 }, "slow", done );
851 this.clock.tick( 600 );
855 "CSS Auto": function( elem, prop ) {
856 jQuery( elem ).addClass( "auto" + prop )
857 .text( "This is a long string of text." );
860 "JS Auto": function( elem, prop ) {
861 jQuery( elem ).css( prop, "" )
862 .text( "This is a long string of text." );
865 "CSS 100": function( elem, prop ) {
866 jQuery( elem ).addClass( "large" + prop );
869 "JS 100": function( elem, prop ) {
870 jQuery( elem ).css( prop, prop === "opacity" ? 1 : "100px" );
871 return prop === "opacity" ? 1 : 100;
873 "CSS 50": function( elem, prop ) {
874 jQuery( elem ).addClass( "med" + prop );
877 "JS 50": function( elem, prop ) {
878 jQuery( elem ).css( prop, prop === "opacity" ? 0.50 : "50px" );
879 return prop === "opacity" ? 0.5 : 50;
881 "CSS 0": function( elem, prop ) {
882 jQuery( elem ).addClass( "no" + prop );
885 "JS 0": function( elem, prop ) {
886 jQuery( elem ).css( prop, prop === "opacity" ? 0 : "0px" );
889 }, function( fn, f ) {
891 "show": function( elem, prop ) {
892 jQuery( elem ).hide( ).addClass( "wide" + prop );
895 "hide": function( elem, prop ) {
896 jQuery( elem ).addClass( "wide" + prop );
899 "100": function( elem, prop ) {
900 jQuery( elem ).addClass( "wide" + prop );
901 return prop === "opacity" ? 1 : 100;
903 "50": function( elem, prop ) {
904 return prop === "opacity" ? 0.50 : 50;
906 "0": function( elem ) {
907 jQuery( elem ).addClass( "noback" );
910 }, function( tn, t ) {
911 test(fn + " to " + tn, function() {
913 elem = jQuery.makeTest( fn + " to " + tn ),
914 t_w = t( elem, "width" ),
915 f_w = f( elem, "width" ),
916 t_h = t( elem, "height" ),
917 f_h = f( elem, "height" ),
918 t_o = t( elem, "opacity" ),
919 f_o = f( elem, "opacity" );
926 // TODO: uncrowd this
927 if ( t_h === "show" ) {num++;}
928 if ( t_w === "show" ) {num++;}
929 if ( t_w === "hide" || t_w === "show" ) {num++;}
930 if ( t_h === "hide" || t_h === "show" ) {num++;}
931 if ( t_o === "hide" || t_o === "show" ) {num++;}
932 if ( t_w === "hide" ) {num++;}
933 if ( t_o.constructor === Number ) {num += 2;}
934 if ( t_w.constructor === Number ) {num += 2;}
935 if ( t_h.constructor === Number ) {num +=2;}
939 anim = { width: t_w, height: t_h, opacity: t_o };
941 elem.animate(anim, 50);
943 jQuery.when( elem ).done(function( elem ) {
944 var cur_o, cur_w, cur_h, old_h;
948 if ( t_w === "show" ) {
949 equal( elem.style.display, "block", "Showing, display should block: " + elem.style.display );
952 if ( t_w === "hide" || t_w === "show" ) {
953 ok( f_w === "" ? elem.style.width === f_w : elem.style.width.indexOf( f_w ) === 0, "Width must be reset to " + f_w + ": " + elem.style.width );
956 if ( t_h === "hide" || t_h === "show" ) {
957 ok( f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf( f_h ) === 0, "Height must be reset to " + f_h + ": " + elem.style.height );
960 cur_o = jQuery.style(elem, "opacity");
962 if ( f_o !== jQuery.css(elem, "opacity") ) {
963 f_o = f( elem, "opacity" );
966 if ( t_o === "hide" || t_o === "show" ) {
967 equal( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o );
970 if ( t_w === "hide" ) {
971 equal( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display );
974 if ( t_o.constructor === Number ) {
975 equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
977 ok( jQuery.css(elem, "opacity") !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
980 if ( t_w.constructor === Number ) {
981 equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
983 cur_w = jQuery.css( elem,"width" );
985 ok( elem.style.width !== "" || cur_w === t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
988 if ( t_h.constructor === Number ) {
989 equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
991 cur_h = jQuery.css( elem,"height" );
993 ok( elem.style.height !== "" || cur_h === t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
996 if ( t_h === "show" ) {
997 old_h = jQuery.css( elem, "height" );
998 jQuery( elem ).append("<br/>Some more text<br/>and some more...");
1000 if ( /Auto/.test( fn ) ) {
1001 notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." );
1003 equal( jQuery.css( elem, "height" ), old_h, "Make sure height is not auto." );
1007 // manually remove generated element
1008 jQuery( elem ).remove();
1011 this.clock.tick( 50 );
1016 test("Effects chaining", function() {
1018 props = [ "opacity", "height", "width", "display", "overflow" ],
1019 setup = function( name, selector ) {
1020 var $el = jQuery( selector );
1021 return $el.data( getProps( $el[0] ) ).data( "name", name );
1023 assert = function() {
1024 var data = jQuery.data( this ),
1028 deepEqual( getProps( this ), data, name );
1030 jQuery.removeData( this );
1032 getProps = function( el ) {
1034 jQuery.each( props, function( i, prop ) {
1035 obj[ prop ] = prop === "overflow" && el.style[ prop ] || jQuery.css( el, prop );
1040 expect( remaining );
1042 setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut("fast").fadeIn( "fast", assert );
1043 setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn("fast").fadeOut( "fast", assert );
1044 setup( ".hide().show()", "#show div" ).hide("fast").show( "fast", assert );
1045 setup( ".show().hide()", "#hide div" ).show("fast").hide( "fast", assert );
1046 setup( ".show().hide(easing)", "#easehide div" ).show("fast").hide( "fast", "linear", assert );
1047 setup( ".toggle().toggle() - in", "#togglein div" ).toggle("fast").toggle( "fast", assert );
1048 setup( ".toggle().toggle() - out", "#toggleout div" ).toggle("fast").toggle( "fast", assert );
1049 setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle("fast").toggle( "fast", "linear", assert );
1050 setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown("fast").slideUp( "fast", assert );
1051 setup( ".slideUp().slideDown()", "#slideup div" ).slideUp("fast").slideDown( "fast", assert );
1052 setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp("fast").slideDown( "fast", "linear", assert );
1053 setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle("fast").slideToggle( "fast", assert );
1054 setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle("fast").slideToggle( "fast", assert );
1055 setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle("fast").fadeToggle( "fast", assert );
1056 setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle("fast").fadeToggle( "fast", assert );
1057 setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", assert );
1058 this.clock.tick( 400 );
1061 jQuery.makeTest = function( text ){
1062 var elem = jQuery("<div></div>")
1063 .attr( "id", "test" + jQuery.makeTest.id++ )
1068 .appendTo("#fx-tests")
1074 jQuery.makeTest.id = 1;
1076 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
1079 var $checkedtest = jQuery("#checkedtest");
1080 $checkedtest.hide().show("fast", function() {
1081 ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
1082 ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
1083 ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
1084 ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
1086 this.clock.tick( 200 );
1089 test( "interrupt toggle", function() {
1092 var longDuration = 2000,
1093 shortDuration = 500,
1095 $elems = jQuery(".chain-test"),
1097 finish = function() {
1100 jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) {
1101 var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each(function() {
1102 // Don't end test until we're done with this element
1105 // Save original property value for comparison
1106 jQuery.data( this, "startVal", jQuery( this ).css( prop ) );
1108 // Expect olddisplay data from our .hide() call below
1109 QUnit.expectJqData( this, "olddisplay" );
1112 // Interrupt a hiding toggle
1113 $methodElems[ method ]( longDuration );
1114 setTimeout(function() {
1115 $methodElems.stop().each(function() {
1116 notEqual( jQuery( this ).css( prop ), jQuery.data( this, "startVal" ), ".stop() before completion of hiding ." + method + "() - #" + this.id );
1120 $methodElems[ method ]( shortDuration, function() {
1122 $elem = jQuery( this ),
1123 startVal = $elem.data("startVal");
1125 $elem.removeData("startVal");
1127 equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
1129 // Interrupt a showing toggle
1130 $elem.hide()[ method ]( longDuration );
1131 setTimeout(function() {
1133 notEqual( $elem.css( prop ), startVal, ".stop() before completion of showing ." + method + "() - #" + id );
1136 $elem[ method ]( shortDuration, function() {
1137 equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
1144 clock.tick(longDuration);
1145 //FIXME untangle the set timeouts
1148 test("animate with per-property easing", function(){
1152 var data = { a:0, b:0, c:0 },
1153 _test1_called = false,
1154 _test2_called = false,
1155 _default_test_called = false,
1157 a: [ 100, "_test1" ],
1158 b: [ 100, "_test2" ],
1162 jQuery.easing["_test1"] = function(p) {
1163 _test1_called = true;
1167 jQuery.easing["_test2"] = function(p) {
1168 _test2_called = true;
1172 jQuery.easing["_default_test"] = function(p) {
1173 _default_test_called = true;
1177 jQuery(data).animate( props, 400, "_default_test", function(){
1179 ok( _test1_called, "Easing function (_test1) called" );
1180 ok( _test2_called, "Easing function (_test2) called" );
1181 ok( _default_test_called, "Easing function (_default) called" );
1182 equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)");
1183 equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)");
1185 this.clock.tick( 400 );
1189 test("animate with CSS shorthand properties", function(){
1192 var _default_count = 0,
1194 propsBasic = { "padding": "10 20 30" },
1195 propsSpecial = { "padding": [ "1 2 3", "_special" ] };
1197 jQuery.easing._default = function(p) {
1204 jQuery.easing._special = function(p) {
1212 .animate( propsBasic, 200, "_default", function() {
1213 equal( this.style.paddingTop, "10px", "padding-top was animated" );
1214 equal( this.style.paddingLeft, "20px", "padding-left was animated" );
1215 equal( this.style.paddingRight, "20px", "padding-right was animated" );
1216 equal( this.style.paddingBottom, "30px", "padding-bottom was animated" );
1217 equal( _default_count, 4, "per-animation default easing called for each property" );
1220 .animate( propsSpecial, 200, "_default", function() {
1221 equal( this.style.paddingTop, "1px", "padding-top was animated again" );
1222 equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
1223 equal( this.style.paddingRight, "2px", "padding-right was animated again" );
1224 equal( this.style.paddingBottom, "3px", "padding-bottom was animated again" );
1225 equal( _default_count, 0, "per-animation default easing not called" );
1226 equal( _special_count, 4, "special easing called for each property" );
1228 jQuery(this).css("padding", "0");
1229 delete jQuery.easing._default;
1230 delete jQuery.easing._special;
1232 this.clock.tick( 400 );
1235 test("hide hidden elements, with animation (bug #7141)", function() {
1238 var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
1239 equal( div.css("display"), "none", "Element is hidden by default" );
1240 div.hide(1, function () {
1241 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
1242 div.show(1, function () {
1243 equal( div.css("display"), "block", "Show a double-hidden element" );
1246 this.clock.tick( 10 );
1249 test("animate unit-less properties (#4966)", 2, function() {
1250 var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
1251 equal( div.css( "z-index" ), "0", "z-index is 0" );
1252 div.animate({ zIndex: 2 }, function() {
1253 equal( div.css( "z-index" ), "2", "z-index is 2" );
1255 this.clock.tick( 400 );
1258 test( "animate properties missing px w/ opacity as last (#9074)", 2, function() {
1261 div = jQuery( "<div style='position: absolute; margin-left: 0; left: 0px;'></div>" )
1262 .appendTo( "#qunit-fixture" );
1263 function cssInt( prop ) {
1264 return parseInt( div.css( prop ), 10 );
1266 equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
1267 equal( cssInt( "left" ), 0, "Left is 0" );
1274 this.clock.tick( 500 );
1276 ml = cssInt( "marginLeft" );
1277 l = cssInt( "left" );
1278 notEqual( ml, 0, "Margin left is not 0 after partial animate" );
1279 notEqual( ml, 200, "Margin left is not 200 after partial animate" );
1280 notEqual( l, 0, "Left is not 0 after partial animate" );
1281 notEqual( l, 200, "Left is not 200 after partial animate" );
1282 div.stop().remove();
1285 test("callbacks should fire in correct order (#9100)", function() {
1291 jQuery("<p data-operation='*2'></p><p data-operation='^2'></p>").appendTo("#qunit-fixture")
1292 // The test will always pass if no properties are animated or if the duration is 0
1293 .animate({fontSize: 12}, 13, function() {
1294 a *= jQuery(this).data("operation") === "*2" ? 2 : a;
1297 equal( a, 4, "test value has been *2 and _then_ ^2");
1300 this.clock.tick( 20 );
1303 test( "callbacks that throw exceptions will be removed (#5684)", function() {
1306 var foo = jQuery( "#foo" );
1308 function TestException() {
1311 foo.animate({ height: 1 }, 1, function() {
1312 throw new TestException();
1315 // this test thoroughly abuses undocumented methods - please feel free to update
1316 // with any changes internally to these functions.
1318 // make sure that the standard timer loop will NOT run.
1321 this.clock.tick( 1 );
1322 raises( jQuery.fx.tick, TestException, "Exception was thrown" );
1324 // the second call shouldn't
1327 ok( true, "Test completed without throwing a second exception" );
1331 test("animate will scale margin properties individually", function() {
1334 var foo = jQuery( "#foo" ).css({
1339 ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "Sanity Check" );
1345 ok( foo.css( "marginLeft") !== foo.css( "marginRight" ), "The margin properties are different");
1347 // clean up for next test
1356 test("Do not append px to 'fill-opacity' #9548", 1, function() {
1357 var $div = jQuery("<div>").appendTo("#qunit-fixture");
1359 $div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () {
1360 equal( jQuery(this).css("fill-opacity"), 1, "Do not append px to 'fill-opacity'");
1365 test("line-height animates correctly (#13855)", 12, function() {
1368 longDuration = 2000,
1369 shortDuration = 500,
1371 "<p style='line-height: 100;'>unitless</p>" +
1372 "<p style='line-height: 5000px;'>px</p>" +
1373 "<p style='line-height: 5000%;'>percent</p>" +
1374 "<p style='line-height: 100em;'>em</p>"
1375 ).appendTo("#qunit-fixture"),
1376 initialHeight = jQuery.map( animated, function( el ) {
1377 return jQuery( el ).height();
1381 // Delay start to improve test stability
1382 setTimeout(function() {
1385 animated.animate( { "line-height": "hide" }, longDuration, "linear" );
1387 setTimeout(function() {
1388 var progress = ( (new Date()) - t0 ) / longDuration;
1390 animated.each(function( i ) {
1391 var label = jQuery.text( this ),
1392 initial = initialHeight[ i ],
1393 height = jQuery( this ).height(),
1394 lower = initial * ( 1 - progress ) / tolerance;
1395 ok( height < initial, "hide " + label + ": upper bound; " +
1396 height + " < " + initial + " @ " + ( progress * 100 ) + "%" );
1397 ok( height > lower, "hide " + label + ": lower bound; " +
1398 height + " > " + lower + " @ " + ( progress * 100 ) + "%" );
1402 animated.stop( true, true ).hide()
1403 .animate( { "line-height": "show" }, longDuration, "linear" );
1405 setTimeout(function() {
1406 var progress = ( (new Date()) - t0 ) / longDuration;
1408 animated.each(function( i ) {
1409 var label = jQuery.text( this ),
1410 initial = initialHeight[ i ],
1411 height = jQuery( this ).height(),
1412 upper = initial * progress * tolerance;
1413 ok( height < upper, "show " + label + ": upper bound; " +
1414 height + " < " + upper + " @ " + ( progress * 100 ) + "%" );
1417 animated.stop( true, true );
1419 clock.tick(shortDuration);
1421 clock.tick(shortDuration);
1426 // Start 1.8 Animation tests
1427 test( "jQuery.Animation( object, props, opts )", 4, function() {
1440 animation = jQuery.Animation( testObject, testDest, { "duration": 1 });
1441 animation.done(function() {
1442 for ( var prop in testDest ) {
1443 equal( testObject[ prop ], testDest[ prop ], "Animated: " + prop );
1445 animation.done(function() {
1446 deepEqual( testObject, testDest, "No unexpected properties" );
1449 this.clock.tick( 10 );
1452 test( "Animate Option: step: function( percent, tween )", 1, function() {
1454 jQuery( "#foo" ).animate({
1460 step: function( value, tween ) {
1461 var calls = counter[ tween.prop ] = counter[ tween.prop ] || [];
1462 // in case this is called multiple times for either, lets store it in
1463 // 0 or 1 in the array
1464 calls[ value === 0 ? 0 : 1 ] = value;
1466 }).queue( function( next ) {
1467 deepEqual( counter, {
1471 }, "Step function was called once at 0% and once at 100% for each property");
1474 this.clock.tick( 10 );
1477 test( "Animate callbacks have correct context", 2, function() {
1478 var foo = jQuery( "#foo" );
1482 equal( foo[ 0 ], this, "Complete callback after stop(true) `this` is element" );
1483 }).stop( true, true );
1487 equal( foo[ 0 ], this, "Complete callback `this` is element" );
1489 this.clock.tick( 10 );
1492 test( "User supplied callback called after show when fx off (#8892)", 2, function() {
1493 var foo = jQuery( "#foo" );
1494 jQuery.fx.off = true;
1496 foo.fadeIn( 500, function() {
1497 ok( jQuery( this ).is( ":visible" ), "Element is visible in callback" );
1498 foo.fadeOut( 500, function() {
1499 ok( jQuery( this ).is( ":hidden" ), "Element is hidden in callback" );
1500 jQuery.fx.off = false;
1503 this.clock.tick( 1000 );
1506 test( "animate should set display for disconnected nodes", function() {
1513 fadeTo: [ "fast", 0.5 ],
1514 slideDown: [ "fast" ],
1516 animate: [{ width: "show" }]
1518 $divTest = jQuery("<div>test</div>"),
1519 // parentNode = null
1520 $divEmpty = jQuery("<div/>"),
1521 $divNone = jQuery("<div style='display: none;'/>"),
1522 $divInline = jQuery("<div style='display: inline;'/>"),
1525 strictEqual( $divTest.show()[ 0 ].style.display, "block", "set display with show() for element with parentNode = document fragment" );
1526 strictEqual( $divEmpty.show()[ 0 ].style.display, "block", "set display with show() for element with parentNode = null" );
1527 strictEqual( $divNone.show()[ 0 ].style.display, "block", "show() should change display if it already set to none" );
1528 strictEqual( $divInline.show()[ 0 ].style.display, "inline", "show() should not change display if it already set" );
1530 QUnit.expectJqData( $divTest[ 0 ], "olddisplay" );
1531 QUnit.expectJqData( $divEmpty[ 0 ], "olddisplay" );
1532 QUnit.expectJqData( $divNone[ 0 ], "olddisplay" );
1534 jQuery.each( methods, function( name, opt ) {
1537 // parentNode = document fragment
1538 jQuery("<div>test</div>"),
1540 // parentNode = null
1544 var callback = [function () {
1545 strictEqual( this.style.display, "block", "set display to block with " + name );
1547 QUnit.expectJqData( this, "olddisplay" );
1550 jQuery.fn[ name ].apply( this, opt.concat( callback ) );
1556 test("Animation callback should not show animated element as :animated (#7157)", 1, function() {
1557 var foo = jQuery( "#foo" );
1561 }, 100, function() {
1562 ok( !foo.is(":animated"), "The element is not animated" );
1564 this.clock.tick( 100 );
1567 test("Initial step callback should show element as :animated (#14623)", 1, function() {
1568 var foo = jQuery( "#foo" );
1575 ok( foo.is(":animated"), "The element matches :animated inside step function" );
1578 this.clock.tick( 1 );
1582 test( "hide called on element within hidden parent should set display to none (#10045)", 3, function() {
1583 var hidden = jQuery(".hidden"),
1584 elems = jQuery("<div>hide</div><div>hide0</div><div>hide1</div>");
1586 hidden.append( elems );
1589 elems.eq( 0 ).hide(),
1590 elems.eq( 1 ).hide( 0 ),
1591 elems.eq( 2 ).hide( 1 )
1593 strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element within hidden parent should set display to none" );
1594 strictEqual( elems.get( 1 ).style.display, "none", "hide( 0 ) called on element within hidden parent should set display to none" );
1595 strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element within hidden parent should set display to none" );
1599 this.clock.tick( 10 );
1602 test( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", 5, function() {
1603 var foo = jQuery("#foo"),
1607 for ( ; i < 5; i++ ) {
1608 elems = elems.add("<div style='width:0;height:0;'></div>");
1611 foo.append( elems );
1614 elems.eq( 0 ).hide(),
1615 elems.eq( 1 ).hide( jQuery.noop ),
1616 elems.eq( 2 ).hide( 1 ),
1617 elems.eq( 3 ).fadeOut(),
1618 elems.eq( 4 ).slideUp()
1620 strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element width height and width = 0 should set display to none" );
1621 strictEqual( elems.get( 1 ).style.display, "none",
1622 "hide( jQuery.noop ) called on element width height and width = 0 should set display to none" );
1623 strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element width height and width = 0 should set display to none" );
1624 strictEqual( elems.get( 3 ).style.display, "none", "fadeOut() called on element width height and width = 0 should set display to none" );
1625 strictEqual( elems.get( 4 ).style.display, "none", "slideUp() called on element width height and width = 0 should set display to none" );
1628 this.clock.tick( 400 );
1631 test( "Handle queue:false promises", 10, function() {
1632 var foo = jQuery( "#foo" ).clone().addBack(),
1640 complete: function() {
1641 ok( step++ <= 2, "Step one or two" );
1647 complete: function() {
1648 ok( step > 2 && step < 5, "Step three or four" );
1653 this.clock.tick( 10 );
1655 foo.promise().done( function() {
1656 equal( step++, 5, "steps 1-5: queue:false then queue:fx done" );
1661 complete: function() {
1662 ok( step > 5 && step < 8, "Step six or seven" );
1670 complete: function() {
1671 ok( step > 7 && step < 10, "Step eight or nine" );
1674 }).promise().done( function() {
1675 equal( step++, 10, "steps 6-10: queue:fx then queue:false" );
1679 this.clock.tick( 10 );
1682 test( "multiple unqueued and promise", 4, function() {
1683 var foo = jQuery( "#foo" ),
1690 complete: function() {
1691 strictEqual( step++, 2, "Step 2" );
1698 complete: function() {
1699 strictEqual( step++, 3, "Step 3" );
1704 complete: function() {
1705 // no properties is a non-op and finishes immediately
1706 strictEqual( step++, 1, "Step 1" );
1708 }).promise().done( function() {
1709 strictEqual( step++, 4, "Step 4" );
1711 this.clock.tick( 1000 );
1714 test( "animate does not change start value for non-px animation (#7109)", 1, function() {
1715 var parent = jQuery( "<div><div></div></div>" ).css({ width: 284, height: 1 }).appendTo( "#qunit-fixture" ),
1716 child = parent.children().css({ fontSize: "98.6in", width: "0.01em", height: 1 }),
1717 actual = parseFloat( child.css( "width" ) ),
1720 child.animate({ width: "0%" }, {
1723 computed.push( parseFloat( child.css( "width" ) ) );
1725 }).queue( function( next ) {
1726 var ratio = computed[ 0 ] / actual;
1727 ok( ratio > 0.9 && ratio < 1.1 , "Starting width was close enough" );
1731 this.clock.tick( 10 );
1734 test( "non-px animation handles non-numeric start (#11971)", 2, function() {
1735 var foo = jQuery("#foo"),
1736 initial = foo.css("backgroundPositionX");
1740 ok( true, "Style property not understood" );
1744 foo.animate({ backgroundPositionX: "42%" }, {
1746 progress: function( anim, percent ) {
1751 if ( parseFloat( initial ) ) {
1752 equal( jQuery.style( this, "backgroundPositionX" ), initial, "Numeric start preserved" );
1754 equal( jQuery.style( this, "backgroundPositionX" ), "0%", "Non-numeric start zeroed" );
1758 equal( jQuery.style( this, "backgroundPositionX" ), "42%", "End reached" );
1761 this.clock.tick( 10 );
1764 test("Animation callbacks (#11797)", 15, function() {
1765 var targets = jQuery("#foo").children(),
1767 expectedProgress = 0;
1769 targets.eq( 0 ).animate( {}, {
1772 ok( true, "empty: start" );
1774 progress: function( anim, percent ) {
1775 equal( percent, 0, "empty: progress 0" );
1778 ok( true, "empty: done" );
1781 ok( false, "empty: fail" );
1783 always: function() {
1784 ok( true, "empty: always" );
1789 ok( done, "empty: done immediately" );
1792 targets.eq( 1 ).animate({
1797 ok( true, "stopped: start" );
1799 progress: function( anim, percent ) {
1800 equal( percent, 0, "stopped: progress 0" );
1803 ok( false, "stopped: done" );
1806 ok( true, "stopped: fail" );
1808 always: function() {
1809 ok( true, "stopped: always" );
1814 ok( done, "stopped: stopped immediately" );
1816 targets.eq( 2 ).animate({
1821 ok( true, "async: start" );
1823 progress: function( anim, percent ) {
1824 // occasionally the progress handler is called twice in first frame.... *shrug*
1825 if ( percent === 0 && expectedProgress === 1 ) {
1828 equal( percent, expectedProgress, "async: progress " + expectedProgress );
1829 // once at 0, once at 1
1833 ok( true, "async: done" );
1836 ok( false, "async: fail" );
1838 always: function() {
1839 ok( true, "async: always" );
1842 this.clock.tick( 10 );
1845 test( "Animate properly sets overflow hidden when animating width/height (#12117)", 8, function() {
1846 jQuery.each( [ "height", "width" ], function( _, prop ) {
1847 jQuery.each( [ 100, 0 ], function( _, value ) {
1848 var div = jQuery("<div>").css( "overflow", "auto" ),
1850 props[ prop ] = value;
1851 div.animate( props, 1 );
1852 equal( div.css( "overflow" ), "hidden",
1853 "overflow: hidden set when animating " + prop + " to " + value );
1855 equal( div.css( "overflow" ), "auto",
1856 "overflow: auto restored after animating " + prop + " to " + value );
1861 test( "Each tick of the timer loop uses a fresh time (#12837)", function() {
1870 step: function( p, fx ) {
1871 ok( fx.now !== lastVal, "Current value is not the last value: " + lastVal + " - " + fx.now );
1875 this.clock.tick( 1 );
1877 // now that we have a new time, run another tick
1880 this.clock.tick( 1 );
1886 test( "Animations with 0 duration don't ease (#12273)", 1, function() {
1887 jQuery.easing.test = function() {
1888 ok( false, "Called easing" );
1891 jQuery( "#foo" ).animate({
1896 complete: function() {
1897 equal( jQuery( this ).height(), 100, "Height is 100" );
1901 delete jQuery.easing.test;
1904 jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
1905 // this test would look a lot better if we were using something to override
1906 // the default timers
1907 var duration = 1500;
1908 test( "toggle state tests: " + method + " (#8685)", function() {
1909 function secondToggle() {
1910 var stopped = parseFloat( element.css( check ) );
1914 step: function( p, fx ) {
1915 if ( fx.pos > 0.1 && fx.prop === check && !tested ) {
1917 equal( fx.start, stopped, check + " starts at " + stopped + " where it stopped" );
1918 equal( fx.end, original, check + " ending value is " + original );
1927 check = method === "slideToggle" ? "height" : "opacity",
1928 element = jQuery("#foo").height( 200 );
1935 step: function( p, fx ) {
1936 if ( fx.pos > 0.1 && fx.prop === check && !tested ) {
1938 original = fx.start;
1939 ok( fx.start !== 0, check + " is starting at " + original + " on first toggle (non-zero)" );
1940 equal( fx.end, 0, check + " is ending at 0 on first toggle" );
1944 always: secondToggle
1946 //FIXME figure out why 470
1947 this.clock.tick( 470 );
1951 test( "jQuery.fx.start & jQuery.fx.stop hook points", function() {
1952 var oldStart = jQuery.fx.start,
1953 oldStop = jQuery.fx.stop,
1954 foo = jQuery({ foo: 0 });
1958 jQuery.fx.start = function() {
1959 ok( true, "start called" );
1961 jQuery.fx.stop = function() {
1962 ok( true, "stop called" );
1966 foo.animate({ foo: 1 }, { queue: false });
1968 foo.animate({ foo: 2 }, { queue: false });
1974 jQuery.fx.start = oldStart;
1975 jQuery.fx.stop = oldStop;
1978 test( ".finish() completes all queued animations", function() {
1985 div = jQuery("<div>");
1989 jQuery.each( animations, function( prop, value ) {
1991 anim[ prop ] = value;
1992 // the delay shouldn't matter at all!
1993 div.css( prop, 1 ).animate( anim, function() {
1994 ok( true, "Called animation callback for " + prop );
1997 equal( div.queue().length, 8, "8 animations in the queue" );
1999 jQuery.each( animations, function( prop, value ) {
2000 equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
2002 equal( div.queue().length, 0, "empty queue when done" );
2003 equal( div.is(":animated"), false, ":animated doesn't match" );
2007 // leaves a "shadow timer" which does nothing around, need to force a tick
2011 test( ".finish( false ) - unqueued animations", function() {
2018 div = jQuery("<div>");
2022 jQuery.each( animations, function( prop, value ) {
2024 anim[ prop ] = value;
2025 div.css( prop, 1 ).animate( anim, {
2027 complete: function() {
2028 ok( true, "Called animation callback for " + prop );
2032 equal( div.queue().length, 0, "0 animations in the queue" );
2033 div.finish( false );
2034 jQuery.each( animations, function( prop, value ) {
2035 equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
2037 equal( div.is(":animated"), false, ":animated doesn't match" );
2041 // leaves a "shadow timer" which does nothing around, need to force a tick
2045 test( ".finish( \"custom\" ) - custom queue animations", function() {
2052 div = jQuery("<div>");
2056 jQuery.each( animations, function( prop, value ) {
2058 anim[ prop ] = value;
2059 div.css( prop, 1 ).animate( anim, {
2061 complete: function() {
2062 ok( true, "Called animation callback for " + prop );
2066 equal( div.queue( "custom" ).length, 4, "4 animations in the queue" );
2067 // start the first animation
2068 div.dequeue( "custom" );
2069 equal( div.is(":animated"), true, ":animated matches" );
2070 div.finish( "custom" );
2071 jQuery.each( animations, function( prop, value ) {
2072 equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
2074 equal( div.is(":animated"), false, ":animated doesn't match" );
2078 // leaves a "shadow timer" which does nothing around, need to force a tick
2082 test( ".finish() calls finish of custom queue functions", function() {
2083 function queueTester( next, hooks ) {
2084 hooks.stop = function( gotoEnd ) {
2086 equal( this, div[0] );
2087 ok( gotoEnd, "hooks.stop(true) called");
2090 var div = jQuery( "<div>" ),
2095 queueTester.finish = function() {
2097 ok( true, "Finish called on custom queue function" );
2100 div.queue( queueTester ).queue( queueTester ).queue( queueTester ).finish();
2102 equal( inside, 1, "1 stop(true) callback" );
2103 equal( outside, 2, "2 finish callbacks" );
2108 test( ".finish() is applied correctly when multiple elements were animated (#13937)", function() {
2111 var elems = jQuery("<a>0</a><a>1</a><a>2</a>");
2113 elems.animate( { opacity: 0 }, 1500 ).animate( { opacity: 1 }, 1500 );
2114 setTimeout(function() {
2115 elems.eq( 1 ).finish();
2116 ok( !elems.eq( 1 ).queue().length, "empty queue for .finish()ed element" );
2117 ok( elems.eq( 0 ).queue().length, "non-empty queue for preceding element" );
2118 ok( elems.eq( 2 ).queue().length, "non-empty queue for following element" );
2122 this.clock.tick( 1500 );
2125 test( "slideDown() after stop() (#13483)", 2, function() {
2126 var ul = jQuery( "<ul style='height: 100px; display: block;'></ul>" )
2127 .appendTo("#qunit-fixture"),
2128 origHeight = ul.height(),
2131 // First test. slideUp() -> stop() in the middle -> slideDown() until the end
2135 ul.slideDown( 1, function() {
2136 equal( ul.height(), origHeight, "slideDown() after interrupting slideUp() with stop(). Height must be in original value" );
2138 // Second test. slideDown() -> stop() in the middle -> slideDown() until the end
2141 ul.slideDown( 1000 );
2145 equal( ul.height(), origHeight, "slideDown() after interrupting slideDown() with stop(). Height must be in original value" );