Skip to content

Commit 5fb2468

Browse files
gnarfscottgonzalez
authored andcommitted
Unit Tests: Cleaning up some code in effects unit tests, removing magic numbers used for animation durations
1 parent a88d55e commit 5fb2468

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

tests/unit/effects/effects_core.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ function notPresent( value, array, message ) {
88
QUnit.push( jQuery.inArray( value, array ) === -1 , value, array, message );
99
}
1010

11-
var animateTime = 15;
11+
// minDuration is used for "short" animate tests where we are only concerned about the final
12+
var minDuration = 15,
13+
14+
// duration is used for "long" animates where we plan on testing properties during animation
15+
duration = 200,
16+
17+
// mid is used for testing in the "middle" of the "duration" animations
18+
mid = duration / 2;
1219

1320
module( "effects.core" );
1421

@@ -31,16 +38,16 @@ $.each( $.effects.effect, function( effect ) {
3138
test++;
3239
equal( point, test, "Queue function fired in order" );
3340
if ( fn ) {
34-
fn ();
41+
fn();
3542
} else {
36-
setTimeout( next, animateTime );
43+
setTimeout( next, minDuration );
3744
}
3845
};
3946
}
40-
41-
hidden.queue( queueTest() ).show( effect, animateTime, queueTest(function() {
47+
48+
hidden.queue( queueTest() ).show( effect, minDuration, queueTest(function() {
4249
equal( hidden.css("display"), "block", "Hidden is shown after .show(\"" +effect+ "\", time)" );
43-
})).queue( queueTest() ).hide( effect, animateTime, queueTest(function() {
50+
})).queue( queueTest() ).hide( effect, minDuration, queueTest(function() {
4451
equal( hidden.css("display"), "none", "Back to hidden after .hide(\"" +effect+ "\", time)" );
4552
})).queue( queueTest(function(next) {
4653
deepEqual( hidden.queue(), ["inprogress"], "Only the inprogress sentinel remains");
@@ -55,8 +62,8 @@ asyncTest( "animateClass works with borderStyle", function() {
5562
var test = $("div.animateClass"),
5663
count = 0;
5764
expect(3);
58-
test.toggleClass("testAddBorder", 20, function() {
59-
test.toggleClass("testAddBorder", 20, function() {
65+
test.toggleClass("testAddBorder", minDuration, function() {
66+
test.toggleClass("testAddBorder", minDuration, function() {
6067
equal( test.css("borderLeftStyle"), "none", "None border set" );
6168
start();
6269
});
@@ -69,35 +76,35 @@ asyncTest( "animateClass works with colors", function() {
6976
var test = $("div.animateClass"),
7077
count = 0;
7178
expect(2);
72-
test.toggleClass("testChangeBackground", 100, function() {
79+
test.toggleClass("testChangeBackground", duration, function() {
7380
present( test.css("backgroundColor"), [ "#ffffff", "rgb(255, 255, 255)" ], "Color is final" );
7481
start();
7582
});
7683
setTimeout(function() {
7784
var color = test.css("backgroundColor");
7885
notPresent( color, [ "#000000", "#ffffff", "rgb(0, 0, 0)", "rgb(255,255,255)" ],
7986
"Color is not endpoints in middle." );
80-
}, 50);
87+
}, mid);
8188
});
8289

8390
asyncTest( "animateClass works with children", function() {
8491
var test = $("div.animateClass"),
8592
h2 = test.find("h2");
86-
93+
8794
expect(4);
88-
test.toggleClass("testChildren", { children: true, duration: 100, complete: function() {
95+
test.toggleClass("testChildren", { children: true, duration: duration, complete: function() {
8996
equal( h2.css("fontSize"), "20px", "Text size is final during complete");
90-
test.toggleClass("testChildren", 100, function() {
97+
test.toggleClass("testChildren", duration, function() {
9198
equal( h2.css("fontSize"), "10px", "Text size revertted after class removed");
9299
start();
93100
});
94101
setTimeout(function() {
95102
equal( h2.css("fontSize"), "20px", "Text size unchanged with children: undefined" );
96-
}, 50);
103+
}, mid);
97104
}});
98105
setTimeout(function() {
99106
notPresent( h2.css("fontSize"), ["10px","20px"], "Font size is neither endpoint when in middle.");
100-
}, 50);
107+
}, mid);
101108
});
102109

103110
})(jQuery);

0 commit comments

Comments
 (0)