3 // Can't test what ain't there
4 if ( !includesModule( "effects" ) ) {
9 oldRaf
= window
.requestAnimationFrame
,
11 inline: function() { jQuery
.style( this, "display", "none" ); },
12 cascade: function() { this.className
= "hidden"; }
15 QUnit
.module( "effects", {
16 beforeEach: function() {
17 this.sandbox
= sinon
.createSandbox();
18 this.clock
= this.sandbox
.useFakeTimers( 505877050 );
19 window
.requestAnimationFrame
= null;
22 afterEach: function() {
23 this.sandbox
.restore();
25 window
.requestAnimationFrame
= oldRaf
;
26 return moduleTeardown
.apply( this, arguments
);
30 QUnit
[ QUnit
.jQuerySelectors
? "test" : "skip" ]( "sanity check", function( assert
) {
32 assert
.equal( jQuery( "#qunit-fixture:visible, #foo:visible" ).length
, 2, "QUnit state is correct for testing effects" );
35 QUnit
.test( "show() basic", function( assert
) {
38 var div
= jQuery( "<div>" ).hide().appendTo( "#qunit-fixture" ).show();
40 assert
.equal( div
.css( "display" ), "block", "Make sure pre-hidden divs show" );
42 // Clean up the detached node
46 QUnit
.test( "show()", function( assert
) {
49 var div
, speeds
, test
,
50 hiddendiv
= jQuery( "div.hidden" );
52 assert
.equal( jQuery
.css( hiddendiv
[ 0 ], "display" ), "none", "hiddendiv is display: none" );
54 hiddendiv
.css( "display", "block" );
55 assert
.equal( jQuery
.css( hiddendiv
[ 0 ], "display" ), "block", "hiddendiv is display: block" );
58 assert
.equal( jQuery
.css( hiddendiv
[ 0 ], "display" ), "block", "hiddendiv is display: block" );
60 hiddendiv
.css( "display", "" );
62 div
= jQuery( "#fx-queue div" ).slice( 0, 4 );
63 div
.show().each( function() {
64 assert
.notEqual( this.style
.display
, "none", "don't change any <div> with display block" );
69 "undefined speed": undefined,
73 jQuery
.each( speeds
, function( name
, speed
) {
75 div
.hide().show( speed
).each( function() {
76 if ( this.style
.display
=== "none" ) {
80 assert
.ok( pass
, "Show with " + name
);
83 jQuery
.each( speeds
, function( name
, speed
) {
85 div
.hide().show( speed
, function() {
88 assert
.ok( pass
, "Show with " + name
+ " does not call animate callback" );
92 "<div id='show-tests'>" +
93 "<div><p><a href='#'></a></p><code></code><pre></pre><span></span></div>" +
94 "<table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table>" +
95 "<ul><li></li></ul></div>"
96 ).appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" );
106 "thead": "table-header-group",
107 "tbody": "table-row-group",
115 jQuery
.each( test
, function( selector
, expected
) {
116 var elem
= jQuery( selector
, "#show-tests" ).show();
117 assert
.equal( elem
.css( "display" ), expected
, "Show using correct display type for " + selector
);
120 jQuery( "#show-tests" ).remove();
122 // Make sure that showing or hiding a text node doesn't cause an error
123 jQuery( "<div>test</div> text <span>test</span>" ).show().remove();
124 jQuery( "<div>test</div> text <span>test</span>" ).hide().remove();
127 supportjQuery
.each( hideOptions
, function( type
, setup
) {
128 QUnit
.test( "show(Number) - " + type
+ " hidden", function( assert
) {
132 "<div id='show-tests'>" +
133 "<div><p><a href='#'></a></p><code></code><pre></pre><span></span></div>" +
134 "<table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody>" +
136 "<ul><li></li></ul></div>"
137 ).appendTo( "#qunit-fixture" ).find( "*" ).each( setup
);
139 // Note: inline elements are expected to be inline-block
140 // because we're showing width/height
141 // Can't animate width/height inline
151 "thead": "table-header-group",
152 "tbody": "table-row-group",
160 jQuery
.each( test
, function( selector
) {
161 jQuery( selector
, "#show-tests" ).show( fxInterval
* 10 );
163 this.clock
.tick( fxInterval
* 5 );
164 jQuery
.each( test
, function( selector
, expected
) {
165 jQuery( selector
, "#show-tests" ).each( function() {
167 jQuery( this ).css( "display" ),
168 expected
=== "inline" ? "inline-block" : expected
,
169 "Correct display type during animation for " + selector
173 this.clock
.tick( fxInterval
* 5 );
174 jQuery
.each( test
, function( selector
, expected
) {
175 jQuery( selector
, "#show-tests" ).each( function() {
176 assert
.equal( jQuery( this ).css( "display" ), expected
,
177 "Correct display type after animation for " + selector
);
181 jQuery( "#show-tests" ).remove();
185 // Supports trac-7397
186 supportjQuery
.each( hideOptions
, function( type
, setup
) {
187 QUnit
.test( "Persist correct display value - " + type
+ " hidden", function( assert
) {
190 jQuery( "<div id='show-tests'><span style='position:absolute;'>foo</span></div>" )
191 .appendTo( "#qunit-fixture" ).find( "*" ).each( setup
);
193 var $span
= jQuery( "#show-tests span" ),
194 displayNone
= $span
.css( "display" ),
200 display
= $span
.css( "display" );
204 $span
.fadeIn( fxInterval
* 10, function() {
205 assert
.equal( $span
.css( "display" ), display
, "Expecting display: " + display
);
206 $span
.fadeOut( fxInterval
* 10, function() {
207 assert
.equal( $span
.css( "display" ), displayNone
, "Expecting display: " + displayNone
);
208 $span
.fadeIn( fxInterval
* 10, function() {
209 assert
.equal( $span
.css( "display" ), display
, "Expecting display: " + display
);
214 clock
.tick( fxInterval
* 30 );
218 // IE doesn't support Shadow DOM.
220 "Persist correct display value - " + type
+ " hidden, shadow child", function( assert
) {
223 jQuery( "<div id='shadowHost'></div>" ).appendTo( "#qunit-fixture" );
225 var shadowHost
= document
.querySelector( "#shadowHost" );
226 var shadowRoot
= shadowHost
.attachShadow( { mode
: "open" } );
227 shadowRoot
.innerHTML
= "<style>.hidden{display: none;}</style>" +
228 "<span id='shadowChild' class='hidden'></span>";
229 var shadowChild
= shadowRoot
.querySelector( "#shadowChild" );
231 var $shadowChild
= jQuery( shadowChild
);
232 var displayNone
= "none";
233 var display
= "inline";
234 var clock
= this.clock
;
236 $shadowChild
.fadeIn( fxInterval
* 10, function() {
237 assert
.equal( $shadowChild
.css( "display" ), display
, "Expecting shadow display: " + display
);
238 $shadowChild
.fadeOut( fxInterval
* 10, function() {
239 assert
.equal( $shadowChild
.css( "display" ), displayNone
, "Expecting shadow display: " + displayNone
);
240 $shadowChild
.fadeIn( fxInterval
* 10, function() {
241 assert
.equal( $shadowChild
.css( "display" ), display
, "Expecting shadow display: " + display
);
246 clock
.tick( fxInterval
* 30 );
250 QUnit
.test( "animate(Hash, Object, Function)", function( assert
) {
252 var hash
= { opacity
: "show" },
253 hashCopy
= jQuery
.extend( {}, hash
);
254 jQuery( "#foo" ).animate( hash
, 0, function() {
255 assert
.equal( hash
.opacity
, hashCopy
.opacity
, "Check if animate changed the hash parameter" );
259 QUnit
.test( "animate relative values", function( assert
) {
263 bases
= [ "%", "px", "em" ],
264 adjustments
= [ "px", "em" ],
265 container
= jQuery( "<div></div>" )
266 .css( { position
: "absolute", height
: "50em", width
: "50em" } ),
267 animations
= bases
.length
* adjustments
.length
;
269 assert
.expect( 2 * animations
);
271 jQuery
.each( bases
, function( _
, baseUnit
) {
272 jQuery
.each( adjustments
, function( _
, adjustUnit
) {
273 var base
= value
+ baseUnit
,
274 adjust
= { height
: "+=2" + adjustUnit
, width
: "-=2" + adjustUnit
},
275 elem
= jQuery( "<div></div>" )
276 .appendTo( container
.clone().appendTo( "#qunit-fixture" ) )
278 position
: "absolute",
280 width
: value
+ adjustUnit
282 baseScale
= elem
[ 0 ].offsetHeight
/ value
,
283 adjustScale
= elem
[ 0 ].offsetWidth
/ value
;
285 elem
.css( "width", base
).animate( adjust
, fxInterval
* 10, function() {
286 assert
.equal( this.offsetHeight
, value
* baseScale
+ 2 * adjustScale
,
287 baseUnit
+ "+=" + adjustUnit
);
288 assert
.equal( this.offsetWidth
, value
* baseScale
- 2 * adjustScale
,
289 baseUnit
+ "-=" + adjustUnit
);
293 clock
.tick( fxInterval
* 10 );
298 QUnit
.test( "animate negative height", function( assert
) {
300 jQuery( "#foo" ).animate( { height
: -100 }, fxInterval
* 10, function() {
301 assert
.equal( this.offsetHeight
, 0, "Verify height." );
303 this.clock
.tick( fxInterval
* 10 );
306 QUnit
.test( "animate negative margin", function( assert
) {
308 jQuery( "#foo" ).animate( { "marginTop": -100 }, fxInterval
* 10, function() {
309 assert
.equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." );
311 this.clock
.tick( fxInterval
* 10 );
314 QUnit
.test( "animate negative margin with px", function( assert
) {
316 jQuery( "#foo" ).animate( { marginTop
: "-100px" }, fxInterval
* 10, function() {
317 assert
.equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." );
319 this.clock
.tick( fxInterval
* 10 );
322 QUnit
.test( "animate negative padding", function( assert
) {
324 jQuery( "#foo" ).animate( { "paddingBottom": -100 }, fxInterval
* 10, function() {
325 assert
.equal( jQuery( this ).css( "paddingBottom" ), "0px", "Verify paddingBottom." );
327 this.clock
.tick( fxInterval
* 10 );
330 QUnit
.test( "animate block as inline width/height", function( assert
) {
333 jQuery( "#foo" ).css( { display
: "inline", width
: "", height
: "" } ).animate( { width
: 42, height
: 42 }, fxInterval
* 10, function() {
334 assert
.equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
335 assert
.equal( this.offsetWidth
, 42, "width was animated" );
336 assert
.equal( this.offsetHeight
, 42, "height was animated" );
338 this.clock
.tick( fxInterval
* 10 );
341 QUnit
.test( "animate native inline width/height", function( assert
) {
344 jQuery( "#foo" ).css( { display
: "", width
: "", height
: "" } )
345 .append( "<span>text</span>" )
347 .animate( { width
: 42, height
: 42 }, fxInterval
* 10, function() {
348 assert
.equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
349 assert
.equal( this.offsetWidth
, 42, "width was animated" );
350 assert
.equal( this.offsetHeight
, 42, "height was animated" );
352 this.clock
.tick( fxInterval
* 10 );
355 QUnit
.test( "animate block width/height", function( assert
) {
358 jQuery( "<div>" ).appendTo( "#qunit-fixture" ).css( {
367 duration
: fxInterval
* 10,
369 if ( jQuery( this ).width() > 42 ) {
370 assert
.ok( false, "width was incorrectly augmented during animation" );
373 complete: function() {
374 assert
.equal( jQuery( this ).css( "display" ), "block", "inline-block was not set on block element when animating width/height" );
375 assert
.equal( jQuery( this ).width(), 42, "width was animated" );
376 assert
.equal( jQuery( this ).height(), 42, "height was animated" );
379 this.clock
.tick( fxInterval
* 10 );
382 QUnit
.test( "animate table width/height", function( assert
) {
385 jQuery( "#table" ).animate( { width
: 42, height
: 42 }, fxInterval
* 10, function() {
386 assert
.equal( jQuery( this ).css( "display" ), "table", "display mode is correct" );
388 this.clock
.tick( fxInterval
* 10 );
391 QUnit
.test( "animate table-row width/height", function( assert
) {
393 var tr
= jQuery( "#table" )
394 .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } )
395 .html( "<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>" )
398 tr
.animate( { width
: 10, height
: 10 }, fxInterval
* 10, function() {
399 assert
.equal( jQuery( this ).css( "display" ), "table-row", "display mode is correct" );
400 assert
.equal( this.offsetWidth
, 20, "width animated to shrink wrap point" );
401 assert
.equal( this.offsetHeight
, 20, "height animated to shrink wrap point" );
403 this.clock
.tick( fxInterval
* 10 );
406 QUnit
.test( "animate table-cell width/height", function( assert
) {
409 var td
= jQuery( "#table" )
410 .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } )
411 .html( "<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>" )
414 td
.animate( { width
: 10, height
: 10 }, fxInterval
* 10, function() {
415 assert
.equal( jQuery( this ).css( "display" ), "table-cell", "display mode is correct" );
416 assert
.equal( this.offsetWidth
, 20, "width animated to shrink wrap point" );
417 assert
.equal( this.offsetHeight
, 20, "height animated to shrink wrap point" );
419 this.clock
.tick( fxInterval
* 10 );
422 QUnit
.test( "animate percentage(%) on width/height", function( assert
) {
425 var $div
= jQuery( "<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>" )
426 .appendTo( "#qunit-fixture" ).children( "div" );
428 $div
.animate( { width
: "25%", height
: "25%" }, fxInterval
, function() {
429 var $this = jQuery( this );
430 assert
.equal( $this.css( "width" ), "15px", "Width was animated to 15px rather than 25px" );
431 assert
.equal( $this.css( "height" ), "15px", "Height was animated to 15px rather than 25px" );
433 this.clock
.tick( fxInterval
* 1.5 );
436 QUnit
.test( "animate resets overflow-x and overflow-y when finished", function( assert
) {
439 .css( { display
: "block", width
: 20, height
: 20, overflowX
: "visible", overflowY
: "auto" } )
440 .animate( { width
: 42, height
: 42 }, fxInterval
* 10, function() {
441 assert
.equal( this.style
.overflowX
, "visible", "overflow-x is visible" );
442 assert
.equal( this.style
.overflowY
, "auto", "overflow-y is auto" );
444 this.clock
.tick( fxInterval
* 10 );
447 QUnit
.test( "animate option { queue: false }", function( assert
) {
449 var foo
= jQuery( "#foo" );
455 duration
: fxInterval
,
456 complete: function() {
457 assert
.ok( true, "Animation Completed" );
460 this.clock
.tick( fxInterval
);
462 assert
.equal( foo
.queue().length
, 0, "Queue is empty" );
465 QUnit
.test( "animate option { queue: true }", function( assert
) {
467 var foo
= jQuery( "#foo" );
473 duration
: fxInterval
,
474 complete: function() {
475 assert
.ok( true, "Animation Completed" );
479 assert
.notEqual( foo
.queue().length
, 0, "Default queue is not empty" );
481 //clear out existing timers before next test
482 this.clock
.tick( fxInterval
);
485 QUnit
.test( "animate option { queue: 'name' }", function( assert
) {
487 var foo
= jQuery( "#foo" ),
488 origWidth
= parseFloat( foo
.css( "width" ) ),
491 foo
.animate( { width
: origWidth
+ 100 }, {
494 complete: function() {
496 // second callback function
498 assert
.equal( parseFloat( foo
.css( "width" ) ), origWidth
+ 100, "Animation ended" );
499 assert
.equal( foo
.queue( "name" ).length
, 1, "Queue length of 'name' queue" );
501 } ).queue( "name", function() {
503 // last callback function
504 assert
.deepEqual( order
, [ 1, 2 ], "Callbacks in expected order" );
507 // this is the first callback function that should be called
509 assert
.equal( parseFloat( foo
.css( "width" ) ), origWidth
, "Animation does not start on its own." );
510 assert
.equal( foo
.queue( "name" ).length
, 2, "Queue length of 'name' queue" );
512 foo
.dequeue( "name" );
513 this.clock
.tick( fxInterval
);
517 QUnit
.test( "animate with no properties", function( assert
) {
521 divs
= jQuery( "div" ),
524 divs
.animate( {}, function() {
528 assert
.equal( divs
.length
, count
, "Make sure that callback is called for each element in the set." );
530 foo
= jQuery( "#foo" );
533 foo
.animate( { top
: 10 }, fxInterval
* 10, function() {
534 assert
.ok( true, "Animation was properly dequeued." );
536 this.clock
.tick( fxInterval
* 10 );
539 QUnit
.test( "animate duration 0", function( assert
) {
543 $elems
= jQuery( [ { a
:0 }, { a
:0 } ] ),
546 assert
.equal( jQuery
.timers
.length
, 0, "Make sure no animation was running from another test" );
548 $elems
.eq( 0 ).animate( { a
:1 }, 0, function() {
549 assert
.ok( true, "Animate a simple property." );
553 // Failed until [6115]
554 assert
.equal( jQuery
.timers
.length
, 0, "Make sure synchronic animations are not left on jQuery.timers" );
556 assert
.equal( counter
, 1, "One synchronic animations" );
558 $elems
.animate( { a
:2 }, 0, function() {
559 assert
.ok( true, "Animate a second simple property." );
563 assert
.equal( counter
, 3, "Multiple synchronic animations" );
565 $elems
.eq( 0 ).animate( { a
:3 }, 0, function() {
566 assert
.ok( true, "Animate a third simple property." );
569 $elems
.eq( 1 ).animate( { a
:3 }, fxInterval
* 20, function() {
572 // Failed until [6115]
573 assert
.equal( counter
, 5, "One synchronic and one asynchronic" );
575 this.clock
.tick( fxInterval
* 20 );
577 $elem
= jQuery( "<div></div>" );
578 $elem
.show( 0, function() {
579 assert
.ok( true, "Show callback with no duration" );
581 $elem
.hide( 0, function() {
582 assert
.ok( true, "Hide callback with no duration" );
585 // manually clean up detached elements
589 QUnit
.test( "animate hyphenated properties", function( assert
) {
593 .css( "font-size", 10 )
594 .animate( { "font-size": 20 }, fxInterval
* 20, function() {
595 assert
.equal( this.style
.fontSize
, "20px", "The font-size property was animated." );
598 // FIXME why is this double only when run with other tests
599 this.clock
.tick( fxInterval
* 40 );
603 QUnit
.test( "animate non-element", function( assert
) {
606 var obj
= { test
: 0 };
608 jQuery( obj
).animate( { test
: 200 }, fxInterval
* 20, function() {
609 assert
.equal( obj
.test
, 200, "The custom property should be modified." );
611 this.clock
.tick( fxInterval
* 20 );
614 QUnit
.test( "animate non-element's zIndex without appending \"px\"", function( assert
) {
617 var obj
= { zIndex
: 0 };
619 jQuery( obj
).animate( { zIndex
: 200 }, fxInterval
* 20, function() {
620 assert
.equal( obj
.zIndex
, 200, "The custom property should be modified without appending \"px\"." );
622 this.clock
.tick( fxInterval
* 20 );
625 QUnit
.test( "stop()", function( assert
) {
629 $foo
= jQuery( "#foo" ),
633 $foo
.hide().css( "width", 200 )
634 .animate( { "width": "show" }, fxInterval
* 150 );
636 this.clock
.tick( fxInterval
* 10 );
637 nw
= $foo
.css( "width" );
638 assert
.notEqual( parseFloat( nw
), w
, "An animation occurred " + nw
+ " " + w
+ "px" );
641 nw
= $foo
.css( "width" );
642 assert
.notEqual( parseFloat( nw
), w
, "Stop didn't reset the animation " + nw
+ " " + w
+ "px" );
644 this.clock
.tick( fxInterval
* 10 );
647 $foo
.removeData( undefined, true );
648 assert
.equal( nw
, $foo
.css( "width" ), "The animation didn't continue" );
650 $one
= jQuery( "#fadein" );
651 $two
= jQuery( "#show" );
652 $one
.fadeTo( fxInterval
* 10, 0, function() {
655 this.clock
.tick( fxInterval
* 10 );
656 $two
.fadeTo( fxInterval
* 10, 0, function() {
657 assert
.equal( $two
.css( "opacity" ), "0", "Stop does not interfere with animations on other elements (trac-6641)" );
660 $one
.add( $two
).css( "opacity", "" );
662 this.clock
.tick( fxInterval
* 10 );
665 QUnit
.test( "stop() - several in queue", function( assert
) {
668 var nw
, $foo
= jQuery( "#foo" );
670 // default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms
671 $foo
.hide().css( "width", 800 );
673 $foo
.animate( { "width": "show" }, 400, "linear" );
674 $foo
.animate( { "width": "hide" } );
675 $foo
.animate( { "width": "show" } );
677 this.clock
.tick( 1 );
680 assert
.equal( $foo
.queue().length
, 3, "3 in the queue" );
682 nw
= $foo
.css( "width" );
683 assert
.notEqual( parseFloat( nw
), 1, "An animation occurred " + nw
);
686 assert
.equal( $foo
.queue().length
, 2, "2 in the queue" );
687 nw
= $foo
.css( "width" );
688 assert
.notEqual( parseFloat( nw
), 1, "Stop didn't reset the animation " + nw
);
692 assert
.equal( $foo
.queue().length
, 0, "0 in the queue" );
695 QUnit
.test( "stop(clearQueue)", function( assert
) {
698 var $foo
= jQuery( "#foo" ),
701 $foo
.hide().css( "width", fxInterval
* 20 ).css( "width" );
703 $foo
.animate( { "width": "show" }, fxInterval
* 100 );
704 $foo
.animate( { "width": "hide" }, fxInterval
* 100 );
705 $foo
.animate( { "width": "show" }, fxInterval
* 100 );
706 this.clock
.tick( fxInterval
* 10 );
707 nw
= $foo
.css( "width" );
708 assert
.ok( parseFloat( nw
) !== w
, "An animation occurred " + nw
+ " " + w
+ "px" );
711 nw
= $foo
.css( "width" );
712 assert
.ok( parseFloat( nw
) !== w
, "Stop didn't reset the animation " + nw
+ " " + w
+ "px" );
714 assert
.equal( $foo
.queue().length
, 0, "The animation queue was cleared" );
715 this.clock
.tick( fxInterval
* 10 );
716 assert
.equal( nw
, $foo
.css( "width" ), "The animation didn't continue" );
719 QUnit
.test( "stop(clearQueue, gotoEnd)", function( assert
) {
722 var $foo
= jQuery( "#foo" ),
725 $foo
.hide().css( "width", fxInterval
* 20 ).css( "width" );
727 $foo
.animate( { width
: "show" }, fxInterval
* 100 );
728 $foo
.animate( { width
: "hide" }, fxInterval
* 100 );
729 $foo
.animate( { width
: "show" }, fxInterval
* 100 );
730 $foo
.animate( { width
: "hide" }, fxInterval
* 100 );
731 this.clock
.tick( fxInterval
* 10 );
732 nw
= $foo
.css( "width" );
733 assert
.ok( parseFloat( nw
) !== w
, "An animation occurred " + nw
+ " " + w
+ "px" );
734 $foo
.stop( false, true );
736 nw
= $foo
.css( "width" );
738 // Disabled, being flaky
739 //equal( nw, 1, "Stop() reset the animation" );
741 this.clock
.tick( fxInterval
* 10 );
743 // Disabled, being flaky
744 //equal( $foo.queue().length, 2, "The next animation continued" );
748 QUnit
.test( "stop( queue, ..., ... ) - Stop single queues", function( assert
) {
751 foo
= jQuery( "#foo" ).css( { width
: 200, height
: 200 } );
756 duration
: fxInterval
* 50,
757 complete: function() {
758 assert
.equal( parseFloat( foo
.css( "width" ) ), 400, "Animation completed for standard queue" );
759 assert
.equal( parseFloat( foo
.css( "height" ) ), saved
, "Height was not changed after the second stop" );
766 duration
: fxInterval
* 100,
768 } ).dequeue( "height" ).stop( "height", false, true );
770 assert
.equal( parseFloat( foo
.css( "height" ) ), 400, "Height was stopped with gotoEnd" );
775 duration
: fxInterval
* 100,
777 } ).dequeue( "height" ).stop( "height", false, false );
778 saved
= parseFloat( foo
.css( "height" ) );
779 this.clock
.tick( fxInterval
* 50 );
782 QUnit
[ QUnit
.jQuerySelectors
? "test" : "skip" ]( "toggle()", function( assert
) {
784 var x
= jQuery( "#foo" );
785 assert
.ok( x
.is( ":visible" ), "is visible" );
787 assert
.ok( x
.is( ":hidden" ), "is hidden" );
789 assert
.ok( x
.is( ":visible" ), "is visible again" );
792 assert
.ok( x
.is( ":visible" ), "is visible" );
794 assert
.ok( x
.is( ":hidden" ), "is hidden" );
796 assert
.ok( x
.is( ":visible" ), "is visible again" );
799 QUnit
.test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", function( assert
) {
802 var div
= jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css( {
804 border
: "5px solid black",
806 marginBottom
: "-11000px"
810 ( new jQuery
.fx( div
, {}, "color" ) ).cur(),
811 jQuery
.css( div
, "color" ),
812 "Return the same value as jQuery.css for complex properties (bug trac-7912)"
816 ( new jQuery
.fx( div
, {}, "borderLeftWidth" ) ).cur(),
818 "Return simple values parsed as Float"
821 // backgroundPosition actually returns 0% 0% in most browser
822 // this fakes a "" return
823 // hook now gets called twice because Tween will grab the current
824 // value as it is being newed
825 jQuery
.cssHooks
.backgroundPosition
= {
827 assert
.ok( true, "hook used" );
833 ( new jQuery
.fx( div
, {}, "backgroundPosition" ) ).cur(),
835 "Return 0 when jQuery.css returns an empty string"
838 delete jQuery
.cssHooks
.backgroundPosition
;
841 ( new jQuery
.fx( div
, {}, "left" ) ).cur(),
843 "Return 0 when jQuery.css returns 'auto'"
847 ( new jQuery
.fx( div
, {}, "marginBottom" ) ).cur(),
849 "support negative values < -10000 (bug trac-7193)"
852 jQuery( div
).remove();
855 QUnit
.test( "Overflow and Display", function( assert
) {
859 testClass
= jQuery
.makeTest( "Overflow and Display" )
860 .addClass( "overflow inline" ),
861 testStyle
= jQuery
.makeTest( "Overflow and Display (inline style)" )
862 .css( { overflow
: "visible", display
: "inline" } ),
864 assert
.equal( jQuery
.css( this, "overflow" ), "visible", "Overflow should be 'visible'" );
865 assert
.equal( jQuery
.css( this, "display" ), "inline", "Display should be 'inline'" );
868 testClass
.add( testStyle
)
869 .addClass( "widewidth" )
870 .text( "Some sample text." )
871 .before( "text before" )
872 .after( "text after" )
873 .animate( { opacity
: 0.5 }, "slow", done
);
874 this.clock
.tick( 600 + fxInterval
);
878 "CSS Auto": function( elem
, prop
) {
879 jQuery( elem
).addClass( "auto" + prop
)
880 .text( "This is a long string of text." );
883 "JS Auto": function( elem
, prop
) {
884 jQuery( elem
).css( prop
, "" )
885 .text( "This is a long string of text." );
888 "CSS 100": function( elem
, prop
) {
889 jQuery( elem
).addClass( "large" + prop
);
892 "JS 100": function( elem
, prop
) {
893 jQuery( elem
).css( prop
, prop
=== "opacity" ? 1 : "100px" );
894 return prop
=== "opacity" ? 1 : 100;
896 "CSS 50": function( elem
, prop
) {
897 jQuery( elem
).addClass( "med" + prop
);
900 "JS 50": function( elem
, prop
) {
901 jQuery( elem
).css( prop
, prop
=== "opacity" ? 0.50 : "50px" );
902 return prop
=== "opacity" ? 0.5 : 50;
904 "CSS 0": function( elem
, prop
) {
905 jQuery( elem
).addClass( "no" + prop
);
908 "JS 0": function( elem
, prop
) {
909 jQuery( elem
).css( prop
, prop
=== "opacity" ? 0 : "0px" );
912 }, function( fn
, f
) {
914 "show": function( elem
, prop
) {
915 jQuery( elem
).hide().addClass( "wide" + prop
);
918 "hide": function( elem
, prop
) {
919 jQuery( elem
).addClass( "wide" + prop
);
922 "100": function( elem
, prop
) {
923 jQuery( elem
).addClass( "wide" + prop
);
924 return prop
=== "opacity" ? 1 : 100;
926 "50": function( elem
, prop
) {
927 return prop
=== "opacity" ? 0.50 : 50;
929 "0": function( elem
) {
930 jQuery( elem
).addClass( "noback" );
933 }, function( tn
, t
) {
934 QUnit
.test( fn
+ " to " + tn
, function( assert
) {
936 elem
= jQuery
.makeTest( fn
+ " to " + tn
),
937 t_w
= t( elem
, "width" ),
938 f_w
= f( elem
, "width" ),
939 t_h
= t( elem
, "height" ),
940 f_h
= f( elem
, "height" ),
941 t_o
= t( elem
, "opacity" ),
942 f_o
= f( elem
, "opacity" );
950 // TODO: uncrowd this
951 if ( t_h
=== "show" ) { num
++; }
952 if ( t_w
=== "show" ) { num
++; }
953 if ( t_w
=== "hide" || t_w
=== "show" ) { num
++; }
954 if ( t_h
=== "hide" || t_h
=== "show" ) { num
++; }
955 if ( t_o
=== "hide" || t_o
=== "show" ) { num
++; }
956 if ( t_w
=== "hide" ) { num
++; }
957 if ( t_o
.constructor === Number
) { num
+= 2; }
958 if ( t_w
.constructor === Number
) { num
+= 2; }
959 if ( t_h
.constructor === Number
) { num
+= 2; }
961 assert
.expect( num
);
963 anim
= { width
: t_w
, height
: t_h
, opacity
: t_o
};
965 elem
.animate( anim
, fxInterval
* 5 );
967 jQuery
.when( elem
).done( function( $elem
) {
968 var cur_o
, cur_w
, cur_h
, old_h
,
971 if ( t_w
=== "show" ) {
972 assert
.equal( $elem
.css( "display" ), "block",
973 "Showing, display should block: " + elem
.style
.display
);
976 if ( t_w
=== "hide" || t_w
=== "show" ) {
977 assert
.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
);
980 if ( t_h
=== "hide" || t_h
=== "show" ) {
981 assert
.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
);
984 cur_o
= jQuery
.style( elem
, "opacity" );
986 if ( f_o
!== jQuery
.css( elem
, "opacity" ) ) {
987 f_o
= f( elem
, "opacity" );
990 if ( t_o
=== "hide" || t_o
=== "show" ) {
991 assert
.equal( cur_o
, f_o
, "Opacity must be reset to " + f_o
+ ": " + cur_o
);
994 if ( t_w
=== "hide" ) {
995 assert
.equal( elem
.style
.display
, "none", "Hiding, display should be none: " + elem
.style
.display
);
998 if ( t_o
.constructor === Number
) {
999 assert
.equal( cur_o
, t_o
, "Final opacity should be " + t_o
+ ": " + cur_o
);
1001 assert
.ok( jQuery
.css( elem
, "opacity" ) !== "" || cur_o
=== t_o
, "Opacity should be explicitly set to " + t_o
+ ", is instead: " + cur_o
);
1004 if ( t_w
.constructor === Number
) {
1005 assert
.equal( elem
.style
.width
, t_w
+ "px", "Final width should be " + t_w
+ ": " + elem
.style
.width
);
1007 cur_w
= jQuery
.css( elem
, "width" );
1009 assert
.ok( elem
.style
.width
!== "" || cur_w
=== t_w
, "Width should be explicitly set to " + t_w
+ ", is instead: " + cur_w
);
1012 if ( t_h
.constructor === Number
) {
1013 assert
.equal( elem
.style
.height
, t_h
+ "px", "Final height should be " + t_h
+ ": " + elem
.style
.height
);
1015 cur_h
= jQuery
.css( elem
, "height" );
1017 assert
.ok( elem
.style
.height
!== "" || cur_h
=== t_h
, "Height should be explicitly set to " + t_h
+ ", is instead: " + cur_h
);
1020 if ( t_h
=== "show" ) {
1021 old_h
= jQuery
.css( elem
, "height" );
1022 jQuery( elem
).append( "<br/>Some more text<br/>and some more..." );
1024 if ( /Auto/.test( fn
) ) {
1025 assert
.notEqual( jQuery
.css( elem
, "height" ), old_h
, "Make sure height is auto." );
1027 assert
.equal( jQuery
.css( elem
, "height" ), old_h
, "Make sure height is not auto." );
1031 // manually remove generated element
1032 jQuery( elem
).remove();
1035 this.clock
.tick( fxInterval
* 10 );
1040 QUnit
.test( "Effects chaining", function( assert
) {
1042 props
= [ "opacity", "height", "width", "display", "overflow" ],
1043 setup = function( name
, selector
) {
1044 var $el
= jQuery( selector
);
1045 return $el
.data( getProps( $el
[ 0 ] ) ).data( "name", name
);
1047 check = function() {
1048 var data
= jQuery
.data( this ),
1052 assert
.deepEqual( getProps( this ), data
, name
);
1054 jQuery
.removeData( this );
1056 getProps = function( el
) {
1058 jQuery
.each( props
, function( i
, prop
) {
1059 obj
[ prop
] = prop
=== "overflow" && el
.style
[ prop
] || jQuery
.css( el
, prop
);
1064 assert
.expect( remaining
);
1066 setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut( "fast" ).fadeIn( "fast", check
);
1067 setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn( "fast" ).fadeOut( "fast", check
);
1068 setup( ".hide().show()", "#show div" ).hide( "fast" ).show( "fast", check
);
1069 setup( ".show().hide()", "#hide div" ).show( "fast" ).hide( "fast", check
);
1070 setup( ".show().hide(easing)", "#easehide div" ).show( "fast" ).hide( "fast", "linear", check
);
1071 setup( ".toggle().toggle() - in", "#togglein div" ).toggle( "fast" ).toggle( "fast", check
);
1072 setup( ".toggle().toggle() - out", "#toggleout div" ).toggle( "fast" ).toggle( "fast", check
);
1073 setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle( "fast" ).toggle( "fast", "linear", check
);
1074 setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown( "fast" ).slideUp( "fast", check
);
1075 setup( ".slideUp().slideDown()", "#slideup div" ).slideUp( "fast" ).slideDown( "fast", check
);
1076 setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp( "fast" ).slideDown( "fast", "linear", check
);
1077 setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle( "fast" ).slideToggle( "fast", check
);
1078 setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle( "fast" ).slideToggle( "fast", check
);
1079 setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle( "fast" ).fadeToggle( "fast", check
);
1080 setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle( "fast" ).fadeToggle( "fast", check
);
1081 setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", check
);
1083 this.clock
.tick( 400 + fxInterval
* 2 );
1086 jQuery
.makeTest = function( text
) {
1087 var elem
= jQuery( "<div></div>" )
1088 .attr( "id", "test" + jQuery
.makeTest
.id
++ )
1091 jQuery( "<h4></h4>" )
1093 .appendTo( "#fx-tests" )
1099 jQuery
.makeTest
.id
= 1;
1101 QUnit
.test( "jQuery.show('fast') doesn't clear radio buttons (bug trac-1095)", function( assert
) {
1104 var $checkedtest
= jQuery( "#checkedtest" );
1105 $checkedtest
.hide().show( "fast", function() {
1106 assert
.ok( jQuery( "input[type='radio']", $checkedtest
).first().attr( "checked" ), "Check first radio still checked." );
1107 assert
.ok( !jQuery( "input[type='radio']", $checkedtest
).last().attr( "checked" ), "Check last radio still NOT checked." );
1108 assert
.ok( jQuery( "input[type='checkbox']", $checkedtest
).first().attr( "checked" ), "Check first checkbox still checked." );
1109 assert
.ok( !jQuery( "input[type='checkbox']", $checkedtest
).last().attr( "checked" ), "Check last checkbox still NOT checked." );
1111 this.clock
.tick( 200 + fxInterval
);
1114 QUnit
.test( "interrupt toggle", function( assert
) {
1115 assert
.expect( 24 );
1117 var longDuration
= fxInterval
* 200,
1118 shortDuration
= fxInterval
* 50,
1120 $elems
= jQuery( ".chain-test" ),
1122 finish = function() {
1125 jQuery
.each( { slideToggle
: "height", fadeToggle
: "opacity", toggle
: "width" }, function( method
, prop
) {
1126 var $methodElems
= $elems
.filter( "[id^='" + method
.toLowerCase() + "']" ).each( function() {
1128 // Don't end test until we're done with this element
1131 // Save original property value for comparison
1132 jQuery
.data( this, "startVal", jQuery( this ).css( prop
) );
1135 // Interrupt a hiding toggle
1136 $methodElems
[ method
]( longDuration
);
1137 setTimeout( function() {
1138 $methodElems
.stop().each( function() {
1139 assert
.notEqual( jQuery( this ).css( prop
), jQuery
.data( this, "startVal" ), ".stop() before completion of hiding ." + method
+ "() - #" + this.id
);
1143 $methodElems
[ method
]( shortDuration
, function() {
1145 $elem
= jQuery( this ),
1146 startVal
= $elem
.data( "startVal" );
1148 $elem
.removeData( "startVal" );
1150 assert
.equal( $elem
.css( prop
), startVal
, "original value restored by ." + method
+ "() - #" + id
);
1152 // Interrupt a showing toggle
1153 $elem
.hide()[ method
]( longDuration
);
1154 setTimeout( function() {
1156 assert
.notEqual( $elem
.css( prop
), startVal
, ".stop() before completion of showing ." + method
+ "() - #" + id
);
1159 $elem
[ method
]( shortDuration
, function() {
1160 assert
.equal( $elem
.css( prop
), startVal
, "original value restored by ." + method
+ "() - #" + id
);
1167 clock
.tick( longDuration
);
1169 // FIXME untangle the set timeouts
1172 QUnit
.test( "animate with per-property easing", function( assert
) {
1176 var data
= { a
: 0, b
: 0, c
: 0 },
1177 test1Called
= false,
1178 test2Called
= false,
1179 defaultTestCalled
= false,
1181 a
: [ 100, "_test1" ],
1182 b
: [ 100, "_test2" ],
1186 jQuery
.easing
._test1 = function( p
) {
1191 jQuery
.easing
._test2 = function( p
) {
1196 jQuery
.easing
._defaultTest = function( p
) {
1197 defaultTestCalled
= true;
1201 jQuery( data
).animate( props
, fxInterval
* 40, "_defaultTest", function() {
1202 assert
.ok( test1Called
, "Easing function (_test1) called" );
1203 assert
.ok( test2Called
, "Easing function (_test2) called" );
1204 assert
.ok( defaultTestCalled
, "Easing function (_default) called" );
1205 assert
.equal( props
.a
[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)" );
1206 assert
.equal( props
.b
[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)" );
1209 this.clock
.tick( fxInterval
* 40 );
1212 QUnit
.test( "animate with CSS shorthand properties", function( assert
) {
1213 assert
.expect( 11 );
1215 var easeAnimation_count
= 0,
1216 easeProperty_count
= 0,
1217 propsBasic
= { "padding": "10 20 30" },
1218 propsSpecial
= { "padding": [ "1 2 3", "propertyScope" ] };
1220 jQuery
.easing
.animationScope = function( p
) {
1222 easeAnimation_count
++;
1227 jQuery
.easing
.propertyScope = function( p
) {
1229 easeProperty_count
++;
1235 .animate( propsBasic
, fxInterval
* 20,
1236 "animationScope", function() {
1237 assert
.equal( this.style
.paddingTop
, "10px", "padding-top was animated" );
1238 assert
.equal( this.style
.paddingLeft
, "20px", "padding-left was animated" );
1239 assert
.equal( this.style
.paddingRight
, "20px", "padding-right was animated" );
1240 assert
.equal( this.style
.paddingBottom
, "30px", "padding-bottom was animated" );
1241 assert
.equal( easeAnimation_count
, 4, "per-animation default easing called for each property" );
1242 easeAnimation_count
= 0;
1244 .animate( propsSpecial
, fxInterval
* 20,
1245 "animationScope", function() {
1246 assert
.equal( this.style
.paddingTop
, "1px", "padding-top was animated again" );
1247 assert
.equal( this.style
.paddingLeft
, "2px", "padding-left was animated again" );
1248 assert
.equal( this.style
.paddingRight
, "2px", "padding-right was animated again" );
1249 assert
.equal( this.style
.paddingBottom
, "3px", "padding-bottom was animated again" );
1250 assert
.equal( easeAnimation_count
, 0, "per-animation default easing not called" );
1251 assert
.equal( easeProperty_count
, 4, "special easing called for each property" );
1253 jQuery( this ).css( "padding", "0" );
1254 delete jQuery
.easing
.animationScope
;
1255 delete jQuery
.easing
.propertyScope
;
1257 this.clock
.tick( fxInterval
* 40 );
1260 QUnit
.test( "hide hidden elements, with animation (bug trac-7141)", function( assert
) {
1263 var div
= jQuery( "<div id='bug7141' style='display:none'></div>" ).appendTo( "#qunit-fixture" );
1264 assert
.equal( div
.css( "display" ), "none", "Element is initially hidden" );
1265 div
.hide( 10, function() {
1266 assert
.equal( div
.css( "display" ), "none", "Element is hidden in .hide() callback" );
1267 div
.show( 11, function() {
1268 assert
.equal( div
.css( "display" ), "block", "Element is visible in .show() callback" );
1271 this.clock
.tick( 50 );
1272 assert
.equal( div
.css( "display" ), "block", "Element is visible after animations" );
1275 QUnit
.test( "animate unit-less properties (trac-4966)", function( assert
) {
1278 var div
= jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
1279 assert
.equal( div
.css( "z-index" ), "0", "z-index is 0" );
1280 div
.animate( { zIndex
: 2 }, function() {
1281 assert
.equal( div
.css( "z-index" ), "2", "z-index is 2" );
1283 this.clock
.tick( 400 + fxInterval
);
1286 QUnit
.test( "animate properties missing px w/ opacity as last (trac-9074)", function( assert
) {
1290 div
= jQuery( "<div style='position: absolute; margin-left: 0; left: 0px;'></div>" )
1291 .appendTo( "#qunit-fixture" );
1292 function cssInt( prop
) {
1293 return parseInt( div
.css( prop
), 10 );
1295 assert
.equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
1296 assert
.equal( cssInt( "left" ), 0, "Left is 0" );
1301 }, fxInterval
* 200 );
1303 this.clock
.tick( fxInterval
* 50 );
1305 ml
= cssInt( "marginLeft" );
1306 l
= cssInt( "left" );
1307 assert
.notEqual( ml
, 0, "Margin left is not 0 after partial animate" );
1308 assert
.notEqual( ml
, 200, "Margin left is not 200 after partial animate" );
1309 assert
.notEqual( l
, 0, "Left is not 0 after partial animate" );
1310 assert
.notEqual( l
, 200, "Left is not 200 after partial animate" );
1311 div
.stop().remove();
1314 QUnit
.test( "callbacks should fire in correct order (trac-9100)", function( assert
) {
1320 jQuery( "<p data-operation='*2'></p><p data-operation='^2'></p>" ).appendTo( "#qunit-fixture" )
1322 // The test will always pass if no properties are animated or if the duration is 0
1323 .animate( { fontSize
: 12 }, fxInterval
, function() {
1324 a
*= jQuery( this ).data( "operation" ) === "*2" ? 2 : a
;
1327 assert
.equal( a
, 4, "test value has been *2 and _then_ ^2" );
1330 this.clock
.tick( fxInterval
* 1.5 );
1333 QUnit
.test( "callbacks that throw exceptions will be removed (trac-5684)", function( assert
) {
1336 var foo
= jQuery( "#foo" );
1338 function TestException() {
1341 foo
.animate( { height
: 1 }, 1, function() {
1342 throw new TestException();
1345 // this test thoroughly abuses undocumented methods - please feel free to update
1346 // with any changes internally to these functions.
1348 // make sure that the standard timer loop will NOT run.
1351 this.clock
.tick( 1 );
1352 assert
.throws( jQuery
.fx
.tick
, TestException
, "Exception was thrown" );
1354 // the second call shouldn't
1357 assert
.ok( true, "Test completed without throwing a second exception" );
1361 QUnit
.test( "animate will scale margin properties individually", function( assert
) {
1364 var foo
= jQuery( "#foo" ).css( {
1369 assert
.ok( foo
.css( "marginLeft" ) !== foo
.css( "marginRight" ), "Sanity Check" );
1375 assert
.ok( foo
.css( "marginLeft" ) !== foo
.css( "marginRight" ), "The margin properties are different" );
1377 // clean up for next test
1386 QUnit
.test( "Do not append px to 'fill-opacity' trac-9548", function( assert
) {
1389 var $div
= jQuery( "<div>" ).appendTo( "#qunit-fixture" );
1391 $div
.css( "fill-opacity", 0 ).animate( { "fill-opacity": 1.0 }, 0, function() {
1392 assert
.equal( jQuery( this ).css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" );
1397 QUnit
.test( "line-height animates correctly (trac-13855)", function( assert
) {
1398 assert
.expect( 12 );
1402 longDuration
= fxInterval
* 200,
1403 shortDuration
= fxInterval
* 50,
1405 "<p style='line-height: 100;'>unitless</p>" +
1406 "<p style='line-height: 5000px;'>px</p>" +
1407 "<p style='line-height: 5000%;'>percent</p>" +
1408 "<p style='line-height: 100em;'>em</p>"
1409 ).appendTo( "#qunit-fixture" ),
1410 initialHeight
= jQuery
.map( animated
, function( el
) {
1411 return jQuery( el
).height();
1415 // Delay start to improve test stability
1416 setTimeout( function() {
1418 t0
= +( new Date() );
1419 animated
.animate( { "line-height": "hide" }, longDuration
, "linear" );
1421 setTimeout( function() {
1422 var progress
= ( ( new Date() ) - t0
) / longDuration
;
1424 animated
.each( function( i
) {
1425 var label
= jQuery
.text( this ),
1426 initial
= initialHeight
[ i
],
1427 height
= jQuery( this ).height(),
1428 lower
= initial
* ( 1 - progress
) / tolerance
;
1429 assert
.ok( height
< initial
, "hide " + label
+ ": upper bound; " +
1430 height
+ " < " + initial
+ " @ " + ( progress
* 100 ) + "%" );
1431 assert
.ok( height
> lower
, "hide " + label
+ ": lower bound; " +
1432 height
+ " > " + lower
+ " @ " + ( progress
* 100 ) + "%" );
1435 t0
= +( new Date() );
1436 animated
.stop( true, true ).hide()
1437 .animate( { "line-height": "show" }, longDuration
, "linear" );
1439 setTimeout( function() {
1440 var progress
= ( ( new Date() ) - t0
) / longDuration
;
1442 animated
.each( function( i
) {
1443 var label
= jQuery
.text( this ),
1444 initial
= initialHeight
[ i
],
1445 height
= jQuery( this ).height(),
1446 upper
= initial
* progress
* tolerance
;
1447 assert
.ok( height
< upper
, "show " + label
+ ": upper bound; " +
1448 height
+ " < " + upper
+ " @ " + ( progress
* 100 ) + "%" );
1451 animated
.stop( true, true );
1453 clock
.tick( shortDuration
);
1455 clock
.tick( shortDuration
);
1456 }, fxInterval
* 5 );
1457 clock
.tick( fxInterval
* 5 );
1460 // Start 1.8 Animation tests
1461 QUnit
.test( "jQuery.Animation( object, props, opts )", function( assert
) {
1476 animation
= jQuery
.Animation( testObject
, testDest
, { "duration": 1 } );
1477 animation
.done( function() {
1478 for ( var prop
in testDest
) {
1479 assert
.equal( testObject
[ prop
], testDest
[ prop
], "Animated: " + prop
);
1481 animation
.done( function() {
1482 assert
.deepEqual( testObject
, testDest
, "No unexpected properties" );
1485 this.clock
.tick( fxInterval
);
1488 QUnit
.test( "Animate Option: step: function( percent, tween )", function( assert
) {
1492 jQuery( "#foo" ).animate( {
1498 step: function( value
, tween
) {
1499 var calls
= counter
[ tween
.prop
] = counter
[ tween
.prop
] || [];
1501 // in case this is called multiple times for either, lets store it in
1502 // 0 or 1 in the array
1503 calls
[ value
=== 0 ? 0 : 1 ] = value
;
1505 } ).queue( function( next
) {
1506 assert
.deepEqual( counter
, {
1510 }, "Step function was called once at 0% and once at 100% for each property" );
1513 this.clock
.tick( fxInterval
);
1516 QUnit
.test( "Animate callbacks have correct context", function( assert
) {
1519 var foo
= jQuery( "#foo" );
1522 }, fxInterval
, function() {
1523 assert
.equal( foo
[ 0 ], this, "Complete callback after stop(true) `this` is element" );
1524 } ).stop( true, true );
1527 }, fxInterval
, function() {
1528 assert
.equal( foo
[ 0 ], this, "Complete callback `this` is element" );
1530 this.clock
.tick( fxInterval
);
1533 QUnit
.test( "User supplied callback called after show when fx off (trac-8892)", function( assert
) {
1536 var foo
= jQuery( "#foo" );
1537 jQuery
.fx
.off
= true;
1539 foo
.fadeIn( 500, function() {
1540 assert
.ok( supportjQuery( this ).is( ":visible" ), "Element is visible in callback" );
1541 foo
.fadeOut( 500, function() {
1542 assert
.ok( supportjQuery( this ).is( ":hidden" ), "Element is hidden in callback" );
1543 jQuery
.fx
.off
= false;
1546 this.clock
.tick( 1000 );
1549 QUnit
.test( "animate should set display for disconnected nodes", function( assert
) {
1550 assert
.expect( 20 );
1554 fadeTo
: [ "fast", 0.5 ],
1555 slideDown
: [ "fast" ],
1557 animate
: [ { width
: "show" } ]
1563 $divEmpty
= jQuery( "<div></div>" ),
1564 $divTest
= jQuery( "<div>test</div>" ),
1565 $divNone
= jQuery( "<div style='display: none;'></div>" ),
1566 $divInline
= jQuery( "<div style='display: inline;'></div>" ),
1567 nullParentDisplay
= $divEmpty
.css( "display" ),
1568 underFragmentDisplay
= $divTest
.css( "display" ),
1571 assert
.strictEqual( $divEmpty
[ 0 ].parentNode
, null, "Setup: element with null parentNode" );
1572 assert
.strictEqual( ( $divTest
[ 0 ].parentNode
|| {} ).nodeType
, 11, "Setup: element under fragment" );
1574 assert
.strictEqual( $divEmpty
.show()[ 0 ].style
.display
, "",
1575 "set display with show() for element with null parentNode" );
1576 assert
.strictEqual( $divTest
.show()[ 0 ].style
.display
, "",
1577 "set display with show() for element under fragment" );
1578 assert
.strictEqual( $divNone
.show()[ 0 ].style
.display
, "",
1579 "show() should change display if it already set to none" );
1580 assert
.strictEqual( $divInline
.show()[ 0 ].style
.display
, "inline",
1581 "show() should not change display if it already set" );
1583 jQuery
.each( showMethods
, function( name
, opt
) {
1584 jQuery
.fn
[ name
].apply( jQuery( "<div></div>" ), opt
.concat( [ function() {
1585 assert
.strictEqual( jQuery( this ).css( "display" ), nullParentDisplay
,
1586 "." + name
+ " block with null parentNode" );
1589 jQuery
.fn
[ name
].apply( jQuery( "<div>test</div>" ), opt
.concat( [ function() {
1590 assert
.strictEqual( jQuery( this ).css( "display" ), underFragmentDisplay
,
1591 "." + name
+ " block under fragment" );
1594 jQuery
.each( toggleMethods
, function( name
, opt
) {
1595 jQuery
.fn
[ name
].apply( jQuery( "<div></div>" ), opt
.concat( [ function() {
1596 assert
.strictEqual( jQuery( this ).css( "display" ), "none",
1597 "." + name
+ " block with null parentNode" );
1600 jQuery
.fn
[ name
].apply( jQuery( "<div>test</div>" ), opt
.concat( [ function() {
1601 assert
.strictEqual( jQuery( this ).css( "display" ), "none",
1602 "." + name
+ " block under fragment" );
1605 clock
.tick( 400 + fxInterval
);
1608 QUnit
[ QUnit
.jQuerySelectors
? "test" : "skip" ]( "Animation callback should not show animated element as :animated (trac-7157)", function( assert
) {
1611 var foo
= jQuery( "#foo" );
1615 }, fxInterval
* 10, function() {
1616 assert
.ok( !foo
.is( ":animated" ), "The element is not animated" );
1618 this.clock
.tick( fxInterval
* 10 );
1621 QUnit
[ QUnit
.jQuerySelectors
? "test" : "skip" ]( "Initial step callback should show element as :animated (trac-14623)", function( assert
) {
1624 var foo
= jQuery( "#foo" );
1631 assert
.ok( foo
.is( ":animated" ), "The element matches :animated inside step function" );
1634 this.clock
.tick( 1 );
1638 QUnit
.test( "hide called on element within hidden parent should set display to none (trac-10045)", function( assert
) {
1641 var hidden
= jQuery( ".hidden" ),
1642 elems
= jQuery( "<div>hide</div><div>hide0</div><div>hide1</div>" );
1644 hidden
.append( elems
);
1647 elems
.eq( 0 ).hide(),
1648 elems
.eq( 1 ).hide( 0 ),
1649 elems
.eq( 2 ).hide( 1 )
1650 ).done( function() {
1651 assert
.strictEqual( elems
.get( 0 ).style
.display
, "none", "hide() called on element within hidden parent should set display to none" );
1652 assert
.strictEqual( elems
.get( 1 ).style
.display
, "none", "hide( 0 ) called on element within hidden parent should set display to none" );
1653 assert
.strictEqual( elems
.get( 2 ).style
.display
, "none", "hide( 1 ) called on element within hidden parent should set display to none" );
1657 this.clock
.tick( fxInterval
);
1660 QUnit
.test( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", function( assert
) {
1663 var foo
= jQuery( "#foo" ),
1667 for ( ; i
< 5; i
++ ) {
1668 elems
= elems
.add( "<div style='width:0;height:0;'></div>" );
1671 foo
.append( elems
);
1674 elems
.eq( 0 ).hide(),
1675 elems
.eq( 1 ).hide( jQuery
.noop
),
1676 elems
.eq( 2 ).hide( 1 ),
1677 elems
.eq( 3 ).fadeOut(),
1678 elems
.eq( 4 ).slideUp()
1679 ).done( function() {
1680 assert
.strictEqual( elems
.get( 0 ).style
.display
, "none", "hide() called on element width height and width = 0 should set display to none" );
1681 assert
.strictEqual( elems
.get( 1 ).style
.display
, "none",
1682 "hide( jQuery.noop ) called on element width height and width = 0 should set display to none" );
1683 assert
.strictEqual( elems
.get( 2 ).style
.display
, "none", "hide( 1 ) called on element width height and width = 0 should set display to none" );
1684 assert
.strictEqual( elems
.get( 3 ).style
.display
, "none", "fadeOut() called on element width height and width = 0 should set display to none" );
1685 assert
.strictEqual( elems
.get( 4 ).style
.display
, "none", "slideUp() called on element width height and width = 0 should set display to none" );
1688 this.clock
.tick( 400 + fxInterval
);
1691 QUnit
.test( "hide should not leave hidden inline elements visible (trac-14848)", function( assert
) {
1694 var el
= jQuery( "#simon1" );
1696 el
.hide( 1, function() {
1697 assert
.equal( el
.css( "display" ), "none", "hidden" );
1698 el
.hide( 1, function() {
1699 assert
.equal( el
.css( "display" ), "none", "still hidden" );
1703 this.clock
.tick( 100 );
1706 QUnit
.test( "Handle queue:false promises", function( assert
) {
1707 assert
.expect( 10 );
1709 var foo
= jQuery( "#foo" ).clone().addBack(),
1715 duration
: fxInterval
,
1717 complete: function() {
1718 assert
.ok( step
++ <= 2, "Step one or two" );
1723 duration
: fxInterval
,
1724 complete: function() {
1725 assert
.ok( step
> 2 && step
< 5, "Step three or four" );
1730 this.clock
.tick( fxInterval
);
1732 foo
.promise().done( function() {
1733 assert
.equal( step
++, 5, "steps 1-5: queue:false then queue:fx done" );
1737 duration
: fxInterval
,
1738 complete: function() {
1739 assert
.ok( step
> 5 && step
< 8, "Step six or seven" );
1745 duration
: fxInterval
,
1747 complete: function() {
1748 assert
.ok( step
> 7 && step
< 10, "Step eight or nine" );
1751 } ).promise().done( function() {
1752 assert
.equal( step
++, 10, "steps 6-10: queue:fx then queue:false" );
1756 this.clock
.tick( fxInterval
);
1759 QUnit
.test( "multiple unqueued and promise", function( assert
) {
1762 var foo
= jQuery( "#foo" ),
1769 complete: function() {
1770 assert
.strictEqual( step
++, 2, "Step 2" );
1777 complete: function() {
1778 assert
.strictEqual( step
++, 3, "Step 3" );
1783 complete: function() {
1785 // no properties is a non-op and finishes immediately
1786 assert
.strictEqual( step
++, 1, "Step 1" );
1788 } ).promise().done( function() {
1789 assert
.strictEqual( step
++, 4, "Step 4" );
1791 this.clock
.tick( 1000 + fxInterval
);
1794 QUnit
.test( "animate does not change start value for non-px animation (trac-7109)", function( assert
) {
1797 var parent
= jQuery( "<div><div></div></div>" ).css( { width
: 284, height
: 1 } ).appendTo( "#qunit-fixture" ),
1798 child
= parent
.children().css( { fontSize
: "98.6in", width
: "0.01em", height
: 1 } ),
1799 actual
= parseFloat( child
.css( "width" ) ),
1802 child
.animate( { width
: "0%" }, {
1805 computed
.push( parseFloat( child
.css( "width" ) ) );
1807 } ).queue( function( next
) {
1808 var ratio
= computed
[ 0 ] / actual
;
1809 assert
.ok( ratio
> 0.9 && ratio
< 1.1,
1810 "Starting width was close enough (" + computed
[ 0 ] + " approximates " + actual
+ ")" );
1814 this.clock
.tick( fxInterval
);
1817 QUnit
.test( "non-px animation handles non-numeric start (trac-11971)", function( assert
) {
1820 var foo
= jQuery( "#foo" ),
1821 initial
= foo
.css( "backgroundPositionX" );
1825 assert
.ok( true, "Style property not understood" );
1829 foo
.animate( { backgroundPositionX
: "42%" }, {
1831 progress: function( anim
, percent
) {
1836 if ( parseFloat( initial
) ) {
1837 assert
.equal( jQuery
.style( this, "backgroundPositionX" ), initial
, "Numeric start preserved" );
1839 assert
.equal( jQuery
.style( this, "backgroundPositionX" ), "0%", "Non-numeric start zeroed" );
1843 assert
.equal( jQuery
.style( this, "backgroundPositionX" ), "42%", "End reached" );
1846 this.clock
.tick( fxInterval
);
1849 QUnit
.test( "Animation callbacks (trac-11797)", function( assert
) {
1850 assert
.expect( 15 );
1853 targets
= jQuery( "#foo" ).children(),
1855 expectedProgress
= 1;
1857 targets
.eq( 0 ).animate( {}, {
1860 assert
.ok( true, "empty: start" );
1862 progress: function( anim
, percent
) {
1863 assert
.equal( percent
, prog
, "empty: progress " + prog
);
1867 assert
.ok( true, "empty: done" );
1870 assert
.ok( false, "empty: fail" );
1872 always: function() {
1873 assert
.ok( true, "empty: always" );
1878 assert
.ok( done
, "empty: done immediately" );
1881 targets
.eq( 1 ).animate( {
1886 assert
.ok( true, "stopped: start" );
1888 progress: function( anim
, percent
) {
1889 assert
.equal( percent
, 0, "stopped: progress 0" );
1892 assert
.ok( false, "stopped: done" );
1895 assert
.ok( true, "stopped: fail" );
1897 always: function() {
1898 assert
.ok( true, "stopped: always" );
1903 assert
.ok( done
, "stopped: stopped immediately" );
1905 targets
.eq( 2 ).animate( {
1910 assert
.ok( true, "async: start" );
1912 progress: function( anim
, percent
) {
1913 assert
.equal( percent
, expectedProgress
, "async: progress " + expectedProgress
);
1917 assert
.ok( true, "async: done" );
1920 assert
.ok( false, "async: fail" );
1922 always: function() {
1923 assert
.ok( true, "async: always" );
1926 this.clock
.tick( fxInterval
);
1929 QUnit
.test( "Animation callbacks in order (gh-2283)", function( assert
) {
1932 var done
= assert
.async(),
1936 jQuery( "#foo" ).animate( {
1941 assert
.step( "start" );
1943 progress: function( anim
, p
, ms
) {
1944 if ( !( step
++ ) ) {
1945 assert
.step( "progress" );
1946 assert
.strictEqual( p
, 0, "first progress callback: progress ratio" );
1947 assert
.strictEqual( ms
, dur
, "first progress callback: remaining ms" );
1949 assert
.step( "last progress" );
1950 assert
.strictEqual( p
, 1, "last progress callback: progress ratio" );
1951 assert
.strictEqual( ms
, 0, "last progress callback: remaining ms" );
1955 assert
.step( "done" );
1958 assert
.ok( false, "Animation failed" );
1960 always: function() {
1961 assert
.verifySteps( [ "start", "progress", "last progress", "done" ] );
1966 this.clock
.tick( dur
+ fxInterval
);
1969 QUnit
.test( "Animate properly sets overflow hidden when animating width/height (trac-12117)", function( assert
) {
1972 jQuery
.each( [ "height", "width" ], function( _
, prop
) {
1973 jQuery
.each( [ 100, 0 ], function( _
, value
) {
1974 var div
= jQuery( "<div>" ).css( "overflow", "auto" ),
1976 props
[ prop
] = value
;
1977 div
.animate( props
, 1 );
1978 assert
.equal( div
.css( "overflow" ), "hidden",
1979 "overflow: hidden set when animating " + prop
+ " to " + value
);
1981 assert
.equal( div
.css( "overflow" ), "auto",
1982 "overflow: auto restored after animating " + prop
+ " to " + value
);
1987 QUnit
.test( "Each tick of the timer loop uses a fresh time (trac-12837)", function( assert
) {
1996 step: function( p
, fx
) {
1997 assert
.ok( fx
.now
!== lastVal
, "Current value is not the last value: " + lastVal
+ " - " + fx
.now
);
2001 this.clock
.tick( 1 );
2003 // now that we have a new time, run another tick
2006 this.clock
.tick( 1 );
2012 QUnit
.test( "Animations with 0 duration don't ease (trac-12273)", function( assert
) {
2015 jQuery
.easing
.test = function() {
2016 assert
.ok( false, "Called easing" );
2019 jQuery( "#foo" ).animate( {
2024 complete: function() {
2025 assert
.equal( jQuery( this ).height(), 100, "Height is 100" );
2029 delete jQuery
.easing
.test
;
2032 jQuery
.map( [ "toggle", "slideToggle", "fadeToggle" ], function( method
) {
2034 // this test would look a lot better if we were using something to override
2035 // the default timers
2036 var duration
= 1500;
2037 QUnit
.test( "toggle state tests: " + method
+ " (trac-8685)", function( assert
) {
2038 function secondToggle() {
2039 var stopped
= parseFloat( element
.css( check
) );
2041 element
[ method
]( {
2043 step: function( p
, fx
) {
2044 if ( fx
.pos
> 0.1 && fx
.prop
=== check
&& !tested
) {
2046 assert
.equal( fx
.start
, stopped
, check
+ " starts at " + stopped
+ " where it stopped" );
2047 assert
.equal( fx
.end
, original
, check
+ " ending value is " + original
);
2056 check
= method
=== "slideToggle" ? "height" : "opacity",
2057 element
= jQuery( "#foo" ).height( 200 );
2061 element
[ method
]( {
2064 step: function( p
, fx
) {
2065 if ( fx
.pos
> 0.1 && fx
.prop
=== check
&& !tested
) {
2067 original
= fx
.start
;
2068 assert
.ok( fx
.start
!== 0, check
+ " is starting at " + original
+ " on first toggle (non-zero)" );
2069 assert
.equal( fx
.end
, 0, check
+ " is ending at 0 on first toggle" );
2073 always
: secondToggle
2076 // FIXME figure out why 470
2077 this.clock
.tick( 470 + fxInterval
* 2 );
2081 QUnit
.test( "jQuery.fx.start & jQuery.fx.stop hook points", function( assert
) {
2082 var oldStart
= jQuery
.fx
.start
,
2083 oldStop
= jQuery
.fx
.stop
,
2084 foo
= jQuery( { foo
: 0 } );
2088 jQuery
.fx
.start = function() {
2089 assert
.ok( true, "start called" );
2091 jQuery
.fx
.stop = function() {
2092 assert
.ok( true, "stop called" );
2096 foo
.animate( { foo
: 1 }, { queue
: false } );
2099 foo
.animate( { foo
: 2 }, { queue
: false } );
2106 jQuery
.fx
.start
= oldStart
;
2107 jQuery
.fx
.stop
= oldStop
;
2110 QUnit
.test( ".finish() completes all queued animations", function( assert
) {
2117 div
= jQuery( "<div>" );
2119 assert
.expect( 11 );
2121 jQuery
.each( animations
, function( prop
, value
) {
2123 anim
[ prop
] = value
;
2125 // the delay shouldn't matter at all!
2126 div
.css( prop
, 1 ).animate( anim
, function() {
2127 assert
.ok( true, "Called animation callback for " + prop
);
2130 assert
.equal( div
.queue().length
, 8, "8 animations in the queue" );
2132 jQuery
.each( animations
, function( prop
, value
) {
2133 assert
.equal( parseFloat( div
.css( prop
) ), value
, prop
+ " finished at correct value" );
2135 assert
.equal( div
.queue().length
, 0, "empty queue when done" );
2137 if ( QUnit
.jQuerySelectors
) {
2138 assert
.equal( div
.is( ":animated" ), false, ":animated doesn't match" );
2140 assert
.ok( "skip", ":animated selector not supported with selector-native" );
2146 // leaves a "shadow timer" which does nothing around, need to force a tick
2150 QUnit
.test( ".finish( false ) - unqueued animations", function( assert
) {
2157 div
= jQuery( "<div>" );
2159 assert
.expect( 10 );
2161 jQuery
.each( animations
, function( prop
, value
) {
2163 anim
[ prop
] = value
;
2164 div
.css( prop
, 1 ).animate( anim
, {
2166 complete: function() {
2167 assert
.ok( true, "Called animation callback for " + prop
);
2171 assert
.equal( div
.queue().length
, 0, "0 animations in the queue" );
2172 div
.finish( false );
2173 jQuery
.each( animations
, function( prop
, value
) {
2174 assert
.equal( parseFloat( div
.css( prop
) ), value
, prop
+ " finished at correct value" );
2177 if ( QUnit
.jQuerySelectors
) {
2178 assert
.equal( div
.is( ":animated" ), false, ":animated doesn't match" );
2180 assert
.ok( "skip", ":animated selector not supported with selector-native" );
2186 // leaves a "shadow timer" which does nothing around, need to force a tick
2190 QUnit
.test( ".finish( \"custom\" ) - custom queue animations", function( assert
) {
2197 div
= jQuery( "<div>" );
2199 assert
.expect( 11 );
2201 jQuery
.each( animations
, function( prop
, value
) {
2203 anim
[ prop
] = value
;
2204 div
.css( prop
, 1 ).animate( anim
, {
2206 complete: function() {
2207 assert
.ok( true, "Called animation callback for " + prop
);
2211 assert
.equal( div
.queue( "custom" ).length
, 4, "4 animations in the queue" );
2213 // start the first animation
2214 div
.dequeue( "custom" );
2216 if ( QUnit
.jQuerySelectors
) {
2217 assert
.equal( div
.is( ":animated" ), true, ":animated matches" );
2219 assert
.ok( "skip", ":animated selector not supported with selector-native" );
2222 div
.finish( "custom" );
2223 jQuery
.each( animations
, function( prop
, value
) {
2224 assert
.equal( parseFloat( div
.css( prop
) ), value
, prop
+ " finished at correct value" );
2227 if ( QUnit
.jQuerySelectors
) {
2228 assert
.equal( div
.is( ":animated" ), false, ":animated doesn't match" );
2230 assert
.ok( "skip", ":animated selector not supported with selector-native" );
2236 // leaves a "shadow timer" which does nothing around, need to force a tick
2240 QUnit
.test( ".finish() calls finish of custom queue functions", function( assert
) {
2241 function queueTester( next
, hooks
) {
2242 hooks
.stop = function( gotoEnd
) {
2244 assert
.equal( this, div
[ 0 ] );
2245 assert
.ok( gotoEnd
, "hooks.stop(true) called" );
2248 var div
= jQuery( "<div>" ),
2253 queueTester
.finish = function() {
2255 assert
.ok( true, "Finish called on custom queue function" );
2258 div
.queue( queueTester
).queue( queueTester
).queue( queueTester
).finish();
2260 assert
.equal( inside
, 1, "1 stop(true) callback" );
2261 assert
.equal( outside
, 2, "2 finish callbacks" );
2266 QUnit
.test( ".finish() is applied correctly when multiple elements were animated (trac-13937)", function( assert
) {
2269 var elems
= jQuery( "<a>0</a><a>1</a><a>2</a>" );
2272 .animate( { opacity
: 0 }, fxInterval
* 150 )
2273 .animate( { opacity
: 1 }, fxInterval
* 150 );
2275 setTimeout( function() {
2276 elems
.eq( 1 ).finish();
2277 assert
.ok( !elems
.eq( 1 ).queue().length
, "empty queue for .finish()ed element" );
2278 assert
.ok( elems
.eq( 0 ).queue().length
, "non-empty queue for preceding element" );
2279 assert
.ok( elems
.eq( 2 ).queue().length
, "non-empty queue for following element" );
2283 this.clock
.tick( fxInterval
* 150 );
2286 QUnit
.test( "slideDown() after stop() (trac-13483)", function( assert
) {
2289 var ul
= jQuery( "<ul style='height: 100px; display: block;'></ul>" )
2290 .appendTo( "#qunit-fixture" ),
2291 origHeight
= ul
.height(),
2294 // First test. slideUp() -> stop() in the middle -> slideDown() until the end
2295 ul
.slideUp( fxInterval
* 100 );
2296 clock
.tick( fxInterval
* 50 );
2298 ul
.slideDown( 1, function() {
2299 assert
.equal( ul
.height(), origHeight
, "slideDown() after interrupting slideUp() with stop(). Height must be in original value" );
2301 // Second test. slideDown() -> stop() in the middle -> slideDown() until the end
2303 clock
.tick( fxInterval
);
2304 ul
.slideDown( fxInterval
* 100 );
2305 clock
.tick( fxInterval
* 50 );
2308 assert
.equal( ul
.height(), origHeight
, "slideDown() after interrupting slideDown() with stop(). Height must be in original value" );
2312 clock
.tick( fxInterval
);
2316 clock
.tick( fxInterval
);
2319 QUnit
.test( "Respect display value on inline elements (trac-14824)", function( assert
) {
2322 var clock
= this.clock
,
2323 fromStyleSheet
= jQuery( "<span id='span-14824'></span>" ),
2324 fromStyleAttr
= jQuery( "<span style='display: block;'></span>" );
2326 jQuery( "#qunit-fixture" ).append( fromStyleSheet
, fromStyleAttr
);
2328 fromStyleSheet
.slideUp( function() {
2329 jQuery( this ).slideDown( function() {
2330 assert
.equal( jQuery( this ).css( "display" ), "block",
2331 "Respect previous display value (from stylesheet) on span element" );
2335 fromStyleAttr
.slideUp( function() {
2336 jQuery( this ).slideDown( function() {
2337 assert
.equal( jQuery( this ).css( "display" ), "block",
2338 "Respect previous display value (from style attribute) on span element" );
2342 clock
.tick( 800 + fxInterval
* 2 );
2345 QUnit
.test( "jQuery.easing._default (gh-2218)", function( assert
) {
2349 .animate( { width
: "5px" }, {
2351 start: function( anim
) {
2352 assert
.equal( anim
.opts
.easing
, jQuery
.easing
._default
,
2353 "anim.opts.easing should be equal to jQuery.easing._default when the easing argument is not given" );
2356 .animate( { height
: "5px" }, {
2359 start: function( anim
) {
2360 assert
.equal( anim
.opts
.easing
, "linear",
2361 "anim.opts.easing should be equal to the easing argument" );
2366 this.clock
.tick( 10 + fxInterval
);
2369 QUnit
.test( "jQuery.easing._default in Animation (gh-2218", function( assert
) {
2373 defaultEasing
= jQuery
.easing
._default
,
2375 testObject
= { "width": 100 },
2376 testDest
= { "width": 200 };
2378 jQuery
.easing
.custom = function( p
) {
2382 jQuery
.easing
._default
= "custom";
2384 animation
= jQuery
.Animation( testObject
, testDest
, { "duration": 1 } );
2385 animation
.done( function() {
2386 assert
.equal( testObject
.width
, testDest
.width
, "Animated width" );
2387 assert
.ok( called
, "Custom jQuery.easing._default called" );
2388 assert
.strictEqual( animation
.opts
.easing
, "custom",
2389 "Animation used custom jQuery.easing._default" );
2390 jQuery
.easing
._default
= defaultEasing
;
2391 delete jQuery
.easing
.custom
;
2394 this.clock
.tick( fxInterval
);
2397 QUnit
.test( "jQuery.easing._default in Tween (gh-2218)", function( assert
) {
2401 defaultEasing
= jQuery
.easing
._default
,
2403 testObject
= { "width": 100 };
2405 jQuery
.easing
.custom = function( p
) {
2409 jQuery
.easing
._default
= "custom";
2411 tween
= jQuery
.Tween( testObject
, { "duration": 1 }, "width", 200 );
2413 assert
.equal( testObject
.width
, 200, "Animated width" );
2414 assert
.ok( called
, "Custom jQuery.easing._default called" );
2415 assert
.strictEqual( tween
.easing
, "custom",
2416 "Animation used custom jQuery.easing._default" );
2417 jQuery
.easing
._default
= defaultEasing
;
2418 delete jQuery
.easing
.custom
;
2421 QUnit
.test( "Display value is correct for disconnected nodes (trac-13310)", function( assert
) {
2424 var div
= jQuery( "<div></div>" );
2426 assert
.equal( div
.css( "display", "inline" ).hide().show().appendTo( "body" ).css( "display" ), "inline", "Initialized display value has returned" );
2429 div
.css( "display", "none" ).hide();
2430 assert
.equal( jQuery
._data( div
[ 0 ], "olddisplay" ), undefined, "olddisplay is undefined after hiding a detached and hidden element" );
2433 div
.css( "display", "inline-block" ).hide().appendTo( "body" ).fadeIn( function() {
2434 assert
.equal( div
.css( "display" ), "inline-block", "Initialized display value has returned" );
2437 this.clock
.tick( 1000 );
2440 QUnit
.test( "Show/hide/toggle and display: inline", function( assert
) {
2441 assert
.expect( 40 );
2443 var clock
= this.clock
;
2445 jQuery( "<span></span><div style='display:inline' title='inline div'></div>" ).each( function() {
2446 var completed
, interrupted
,
2447 N
= fxInterval
* 10,
2448 fixture
= jQuery( "#qunit-fixture" ),
2449 $el
= jQuery( this ),
2450 kind
= this.title
|| this.nodeName
.toLowerCase();
2452 // Animations allowed to complete
2453 completed
= jQuery
.map( [
2454 $el
.clone().data( { call
: "hide", done
: "none" } ).appendTo( fixture
).hide( N
),
2455 $el
.clone().data( { call
: "toggle", done
: "none" } ).appendTo( fixture
).toggle( N
),
2456 $el
.clone().data( { call
: "hide+show", done
: "inline" } ).appendTo( fixture
)
2458 $el
.clone().data( { call
: "hide+toggle", done
: "inline" } ).appendTo( fixture
)
2460 ], function( $clone
) { return $clone
[ 0 ]; } );
2462 // Animations not allowed to complete
2463 interrupted
= jQuery
.map( [
2464 $el
.clone().data( { call
: "hide+stop" } ).appendTo( fixture
).hide( N
),
2465 $el
.clone().data( { call
: "toggle+stop" } ).appendTo( fixture
).toggle( N
),
2466 $el
.clone().data( { call
: "hide+show+stop" } ).appendTo( fixture
).hide().show( N
),
2467 $el
.clone().data( { call
: "hide+toggle+stop" } ).appendTo( fixture
).hide().toggle( N
)
2468 ], function( $clone
) { return $clone
[ 0 ]; } );
2470 // All elements should be inline-block during the animation
2471 clock
.tick( N
/ 2 );
2472 jQuery( completed
).each( function() {
2473 var $el
= jQuery( this ),
2474 call
= $el
.data( "call" );
2475 assert
.strictEqual( $el
.css( "display" ), "inline-block", kind
+ " display during " + call
);
2478 // Interrupted elements should remain inline-block
2479 jQuery( interrupted
).stop();
2480 clock
.tick( N
/ 2 );
2481 jQuery( interrupted
).each( function() {
2482 var $el
= jQuery( this ),
2483 call
= $el
.data( "call" );
2484 assert
.strictEqual( $el
.css( "display" ), "inline-block", kind
+ " display after " + call
);
2487 // Completed elements should not remain inline-block
2488 clock
.tick( N
/ 2 );
2489 jQuery( completed
).each( function() {
2490 var $el
= jQuery( this ),
2491 call
= $el
.data( "call" ),
2492 display
= $el
.data( "done" );
2493 assert
.strictEqual( $el
.css( "display" ), display
, kind
+ " display after " + call
);
2496 // A post-animation toggle should not make any element inline-block
2497 completed
= jQuery( completed
.concat( interrupted
) );
2498 completed
.toggle( N
/ 2 );
2500 completed
.each( function() {
2501 var $el
= jQuery( this ),
2502 call
= $el
.data( "call" );
2503 assert
.ok( $el
.css( "display" ) !== "inline-block",
2504 kind
+ " display is not inline-block after " + call
+ "+toggle" );
2509 function testEasing( assert
, speed
, easing
, complete
) {
2511 var options
= jQuery
.speed( speed
, easing
, complete
);
2513 assert
.equal( options
.duration
, fxInterval
, "Duration set properly" );
2515 typeof options
.easing
=== "function" ? options
.easing() : options
.easing
,
2517 "Easing set properly"
2519 assert
.equal( options
.queue
, "fx", "Queue defaults to fx" );
2523 QUnit
.test( "jQuery.speed( speed, easing, complete )", function( assert
) {
2524 testEasing( assert
, fxInterval
, "linear", function() {
2525 assert
.ok( true, "Complete called" );
2529 QUnit
.test( "jQuery.speed( speed, easing, complete ) - with easing function", function( assert
) {
2537 assert
.ok( true, "Complete called" );
2542 QUnit
.test( "jQuery.speed( options )", function( assert
) {
2543 testEasing( assert
, {
2544 duration
: fxInterval
,
2546 complete: function() {
2547 assert
.ok( true, "Complete called" );
2552 QUnit
.test( "jQuery.speed( options ) - with easing function", function( assert
) {
2553 testEasing( assert
, {
2554 duration
: fxInterval
,
2555 easing: function() {
2558 complete: function() {
2559 assert
.ok( true, "Complete called" );
2564 QUnit
.test( "jQuery.speed( options ) - queue values", function( assert
) {
2567 var get = function( queue
) {
2568 return jQuery
.speed( { queue
: queue
} ).queue
;
2571 assert
.equal( get( null ), "fx", "null defaults to 'fx'" );
2572 assert
.equal( get( undefined ), "fx", "undefined defaults to 'fx'" );
2573 assert
.equal( get( true ), "fx", "true defaults to 'fx'" );
2574 assert
.equal( get( "fx" ), "fx", "'fx' passed through" );
2575 assert
.equal( get( "custom" ), "custom", "'custom' passed through" );
2578 QUnit
.test( "jQuery.speed() - durations", function( assert
) {
2581 var get = function( duration
) {
2582 return jQuery
.speed( duration
).duration
;
2585 assert
.equal( get( 100 ), 100, "jQuery.speed sets number duration" );
2586 assert
.equal( get(), jQuery
.fx
.speeds
._default
, "jQuery.speed falls back default duration" );
2587 assert
.equal( get( "slow" ), jQuery
.fx
.speeds
.slow
, "jQuery.speed uses preset speeds" );
2588 assert
.equal( get( "fast" ), jQuery
.fx
.speeds
.fast
, "jQuery.speed uses preset speeds" );
2589 jQuery
.fx
.off
= true;
2590 assert
.equal( get( 100 ), 0, "jQuery.speed defaults duration to zero if fx is off" );
2591 jQuery
.fx
.off
= false;