Skip to content

Commit

Permalink
Unit Tests: Cleaning up some code in effects unit tests, removing mag…
Browse files Browse the repository at this point in the history
…ic numbers used for animation durations
  • Loading branch information
gnarf authored and scottgonzalez committed May 17, 2011
1 parent a88d55e commit 5fb2468
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions tests/unit/effects/effects_core.js
Expand Up @@ -8,7 +8,14 @@ function notPresent( value, array, message ) {
QUnit.push( jQuery.inArray( value, array ) === -1 , value, array, message ); QUnit.push( jQuery.inArray( value, array ) === -1 , value, array, message );
} }


var animateTime = 15; // minDuration is used for "short" animate tests where we are only concerned about the final
var minDuration = 15,

// duration is used for "long" animates where we plan on testing properties during animation
duration = 200,

// mid is used for testing in the "middle" of the "duration" animations
mid = duration / 2;


module( "effects.core" ); module( "effects.core" );


Expand All @@ -31,16 +38,16 @@ $.each( $.effects.effect, function( effect ) {
test++; test++;
equal( point, test, "Queue function fired in order" ); equal( point, test, "Queue function fired in order" );
if ( fn ) { if ( fn ) {
fn (); fn();
} else { } else {
setTimeout( next, animateTime ); setTimeout( next, minDuration );
} }
}; };
} }

hidden.queue( queueTest() ).show( effect, animateTime, queueTest(function() { hidden.queue( queueTest() ).show( effect, minDuration, queueTest(function() {
equal( hidden.css("display"), "block", "Hidden is shown after .show(\"" +effect+ "\", time)" ); equal( hidden.css("display"), "block", "Hidden is shown after .show(\"" +effect+ "\", time)" );
})).queue( queueTest() ).hide( effect, animateTime, queueTest(function() { })).queue( queueTest() ).hide( effect, minDuration, queueTest(function() {
equal( hidden.css("display"), "none", "Back to hidden after .hide(\"" +effect+ "\", time)" ); equal( hidden.css("display"), "none", "Back to hidden after .hide(\"" +effect+ "\", time)" );
})).queue( queueTest(function(next) { })).queue( queueTest(function(next) {
deepEqual( hidden.queue(), ["inprogress"], "Only the inprogress sentinel remains"); deepEqual( hidden.queue(), ["inprogress"], "Only the inprogress sentinel remains");
Expand All @@ -55,8 +62,8 @@ asyncTest( "animateClass works with borderStyle", function() {
var test = $("div.animateClass"), var test = $("div.animateClass"),
count = 0; count = 0;
expect(3); expect(3);
test.toggleClass("testAddBorder", 20, function() { test.toggleClass("testAddBorder", minDuration, function() {
test.toggleClass("testAddBorder", 20, function() { test.toggleClass("testAddBorder", minDuration, function() {
equal( test.css("borderLeftStyle"), "none", "None border set" ); equal( test.css("borderLeftStyle"), "none", "None border set" );
start(); start();
}); });
Expand All @@ -69,35 +76,35 @@ asyncTest( "animateClass works with colors", function() {
var test = $("div.animateClass"), var test = $("div.animateClass"),
count = 0; count = 0;
expect(2); expect(2);
test.toggleClass("testChangeBackground", 100, function() { test.toggleClass("testChangeBackground", duration, function() {
present( test.css("backgroundColor"), [ "#ffffff", "rgb(255, 255, 255)" ], "Color is final" ); present( test.css("backgroundColor"), [ "#ffffff", "rgb(255, 255, 255)" ], "Color is final" );
start(); start();
}); });
setTimeout(function() { setTimeout(function() {
var color = test.css("backgroundColor"); var color = test.css("backgroundColor");
notPresent( color, [ "#000000", "#ffffff", "rgb(0, 0, 0)", "rgb(255,255,255)" ], notPresent( color, [ "#000000", "#ffffff", "rgb(0, 0, 0)", "rgb(255,255,255)" ],
"Color is not endpoints in middle." ); "Color is not endpoints in middle." );
}, 50); }, mid);
}); });


asyncTest( "animateClass works with children", function() { asyncTest( "animateClass works with children", function() {
var test = $("div.animateClass"), var test = $("div.animateClass"),
h2 = test.find("h2"); h2 = test.find("h2");

expect(4); expect(4);
test.toggleClass("testChildren", { children: true, duration: 100, complete: function() { test.toggleClass("testChildren", { children: true, duration: duration, complete: function() {
equal( h2.css("fontSize"), "20px", "Text size is final during complete"); equal( h2.css("fontSize"), "20px", "Text size is final during complete");
test.toggleClass("testChildren", 100, function() { test.toggleClass("testChildren", duration, function() {
equal( h2.css("fontSize"), "10px", "Text size revertted after class removed"); equal( h2.css("fontSize"), "10px", "Text size revertted after class removed");
start(); start();
}); });
setTimeout(function() { setTimeout(function() {
equal( h2.css("fontSize"), "20px", "Text size unchanged with children: undefined" ); equal( h2.css("fontSize"), "20px", "Text size unchanged with children: undefined" );
}, 50); }, mid);
}}); }});
setTimeout(function() { setTimeout(function() {
notPresent( h2.css("fontSize"), ["10px","20px"], "Font size is neither endpoint when in middle."); notPresent( h2.css("fontSize"), ["10px","20px"], "Font size is neither endpoint when in middle.");
}, 50); }, mid);
}); });


})(jQuery); })(jQuery);

0 comments on commit 5fb2468

Please sign in to comment.