Skip to content

Commit

Permalink
Effects: Updating unit tests to use some more stable logic hopefully
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarf committed Apr 30, 2012
1 parent 1da2bf0 commit fe55b6c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 36 deletions.
93 changes: 67 additions & 26 deletions tests/unit/effects/effects_core.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,38 +61,79 @@ asyncTest( "animateClass works with borderStyle", function() {


asyncTest( "animateClass works with colors", function() { asyncTest( "animateClass works with colors", function() {
var test = $("div.animateClass"), var test = $("div.animateClass"),
count = 0; count = 0,
oldStep = jQuery.fx.step.backgroundColor;
expect(2); expect(2);
test.toggleClass("testChangeBackground", duration, function() {
present( test.css("backgroundColor"), [ "#ffffff", "#fff", "rgb(255, 255, 255)" ], "Color is final" ); // we want to catch the first frame of animation
start(); jQuery.fx.step.backgroundColor = function( fx ) {
oldStep.apply( this, arguments );

// make sure it has animated somewhere we can detect
if ( fx.pos > 255 / 2000 ) {
jQuery.fx.step.backgroundColor = oldStep;
notPresent( test.css("backgroundColor"),
[ "#000000", "#ffffff", "#000", "#fff", "rgb(0, 0, 0)", "rgb(255,255,255)" ],
"Color is not endpoints in middle." );
test.stop( true, true );
}
};

test.toggleClass("testChangeBackground", {
duration: 2000,
complete: function() {
present( test.css("backgroundColor"), [ "#ffffff", "#fff", "rgb(255, 255, 255)" ], "Color is final" );
start();
}
}); });
setTimeout(function() {
var color = test.css("backgroundColor");
notPresent( color, [ "#000000", "#ffffff", "#000", "#fff", "rgb(0, 0, 0)", "rgb(255,255,255)" ],
"Color is not endpoints in middle." );
}, mid);
}); });


asyncTest( "animateClass works with children", function() { asyncTest( "animateClass calls step option", 1, function() {
var test = $("div.animateClass"), var test = jQuery("div.animateClass"),
h2 = test.find("h2"); done = function() {
done = jQuery.noop;
test.stop();
start();
};
test.toggleClass( "testChangeBackground", {
step: function( fx ) {
ok( true, "Step Function Called" );
setTimeout( done, 0 );
}
});
});


expect(4); asyncTest( "animateClass works with children", 3, function() {
setTimeout(function() { var animatedChild,
notPresent( h2.css("fontSize"), ["10px","20px"], "Font size is neither endpoint when in middle."); test = $("div.animateClass"),
}, mid); h2 = test.find("h2");
test.toggleClass("testChildren", { children: true, duration: duration, complete: function() {
equal( h2.css("fontSize"), "20px", "Text size is final during complete");
test.toggleClass("testChildren", duration, function() {
equal( h2.css("fontSize"), "10px", "Text size revertted after class removed");


start(); test.toggleClass("testChildren", {
}); children: true,
setTimeout(function() { duration: duration,
equal( h2.css("fontSize"), "20px", "Text size unchanged during animate with children: undefined" ); complete: function() {
}, mid); equal( h2.css("fontSize"), "20px", "Text size is final during complete");
}}); test.toggleClass("testChildren", {
duration: duration,
complete: function() {
equal( h2.css("fontSize"), "10px", "Text size revertted after class removed");

start();
},
step: function( val, fx ) {
if ( fx.elem === h2[ 0 ] ) {
ok( false, "Error - Animating property on h2" );
}
}
});
},
step: function( val, fx ) {
if ( fx.prop === "fontSize" && fx.elem === h2[ 0 ] && !animatedChild ) {
equal( fx.end, 20, "animating font size on child" );
animatedChild = true;
}
}
});
}); });


asyncTest( "animateClass clears style properties when stopped", function() { asyncTest( "animateClass clears style properties when stopped", function() {
Expand Down
19 changes: 9 additions & 10 deletions ui/jquery.effects.core.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -268,16 +268,15 @@ $.effects.animateClass = function( value, duration, easing, callback ) {
// map all animated objects again - this time collecting a promise // map all animated objects again - this time collecting a promise
allAnimations = allAnimations.map(function() { allAnimations = allAnimations.map(function() {
var styleInfo = this, var styleInfo = this,
dfd = $.Deferred(); dfd = $.Deferred(),

opts = jQuery.extend({}, o, {
this.el.animate( this.diff, { queue: false,
duration: o.duration, complete: function() {
easing: o.easing, dfd.resolve( styleInfo )
queue: false, }
complete: function() { });
dfd.resolve( styleInfo );
} this.el.animate( this.diff, opts );
});
return dfd.promise(); return dfd.promise();
}); });


Expand Down

0 comments on commit fe55b6c

Please sign in to comment.