Skip to content

Commit 6d7ef56

Browse files
committed
Effects: add tests for jQuery.easing._default in Animation and Tween
Ref gh-2219
1 parent 5f2ea40 commit 6d7ef56

File tree

1 file changed

+80
-25
lines changed

1 file changed

+80
-25
lines changed

test/unit/effects.js

Lines changed: 80 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,49 +1130,49 @@ test( "interrupt toggle", function() {
11301130
});
11311131
}, shortDuration );
11321132
});
1133-
clock.tick(longDuration);
1134-
//FIXME untangle the set timeouts
1133+
clock.tick( longDuration );
1134+
1135+
// FIXME untangle the set timeouts
11351136
});
11361137

1137-
test("animate with per-property easing", function(){
1138+
test( "animate with per-property easing", function() {
11381139

1139-
expect(5);
1140+
expect( 5 );
11401141

1141-
var data = { a:0, b:0, c:0 },
1142-
_test1_called = false,
1143-
_test2_called = false,
1144-
_default_test_called = false,
1142+
var data = { a: 0, b: 0, c: 0 },
1143+
test1Called = false,
1144+
test2Called = false,
1145+
defaultTestCalled = false,
11451146
props = {
11461147
a: [ 100, "_test1" ],
11471148
b: [ 100, "_test2" ],
11481149
c: 100
11491150
};
11501151

1151-
jQuery.easing["_test1"] = function(p) {
1152-
_test1_called = true;
1152+
jQuery.easing._test1 = function( p ) {
1153+
test1Called = true;
11531154
return p;
11541155
};
11551156

1156-
jQuery.easing["_test2"] = function(p) {
1157-
_test2_called = true;
1157+
jQuery.easing._test2 = function( p ) {
1158+
test2Called = true;
11581159
return p;
11591160
};
11601161

1161-
jQuery.easing["_default_test"] = function(p) {
1162-
_default_test_called = true;
1162+
jQuery.easing._defaultTest = function( p ) {
1163+
defaultTestCalled = true;
11631164
return p;
11641165
};
11651166

1166-
jQuery(data).animate( props, 400, "_default_test", function(){
1167-
1168-
ok( _test1_called, "Easing function (_test1) called" );
1169-
ok( _test2_called, "Easing function (_test2) called" );
1170-
ok( _default_test_called, "Easing function (_default) called" );
1171-
equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)");
1172-
equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)");
1167+
jQuery( data ).animate( props, 400, "_defaultTest", function() {
1168+
ok( test1Called, "Easing function (_test1) called" );
1169+
ok( test2Called, "Easing function (_test2) called" );
1170+
ok( defaultTestCalled, "Easing function (_default) called" );
1171+
equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)" );
1172+
equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)" );
11731173
});
1174-
this.clock.tick( 400 );
11751174

1175+
this.clock.tick( 400 );
11761176
});
11771177

11781178
test("animate with CSS shorthand properties", function(){
@@ -2212,16 +2212,18 @@ test( "Animation should go to its end state if document.hidden = true", 1, funct
22122212
}
22132213
});
22142214

2215-
test( "jQuery.easing._default (#2218)", 2, function() {
2215+
test( "jQuery.easing._default (gh-2218)", function() {
2216+
expect( 2 );
2217+
22162218
jQuery( "#foo" )
2217-
.animate({ width: "5px" }, {
2219+
.animate( { width: "5px" }, {
22182220
duration: 5,
22192221
start: function( anim ) {
22202222
equal( anim.opts.easing, jQuery.easing._default,
22212223
"anim.opts.easing should be equal to jQuery.easing._default when the easing argument is not given" );
22222224
}
22232225
})
2224-
.animate({ height: "5px" }, {
2226+
.animate( { height: "5px" }, {
22252227
duration: 5,
22262228
easing: "linear",
22272229
start: function( anim ) {
@@ -2230,7 +2232,60 @@ test( "jQuery.easing._default (#2218)", 2, function() {
22302232
}
22312233
})
22322234
.stop();
2235+
22332236
this.clock.tick( 25 );
22342237
});
22352238

2239+
test( "jQuery.easing._default in Animation (gh-2218", function() {
2240+
expect( 3 );
2241+
2242+
var animation,
2243+
defaultEasing = jQuery.easing._default,
2244+
called = false,
2245+
testObject = { "width": 100 },
2246+
testDest = { "width": 200 };
2247+
2248+
jQuery.easing.custom = function( p ) {
2249+
called = true;
2250+
return p;
2251+
};
2252+
jQuery.easing._default = "custom";
2253+
2254+
animation = jQuery.Animation( testObject, testDest, { "duration": 1 } );
2255+
animation.done( function() {
2256+
equal( testObject.width, testDest.width, "Animated width" );
2257+
ok( called, "Custom jQuery.easing._default called" );
2258+
strictEqual( animation.opts.easing, "custom",
2259+
"Animation used custom jQuery.easing._default" );
2260+
jQuery.easing._default = defaultEasing;
2261+
delete jQuery.easing.custom;
2262+
});
2263+
2264+
this.clock.tick( 10 );
2265+
});
2266+
2267+
test( "jQuery.easing._default in Tween (gh-2218)", function() {
2268+
expect( 3 );
2269+
2270+
var tween,
2271+
defaultEasing = jQuery.easing._default,
2272+
called = false,
2273+
testObject = { "width": 100 };
2274+
2275+
jQuery.easing.custom = function( p ) {
2276+
called = true;
2277+
return p;
2278+
};
2279+
jQuery.easing._default = "custom";
2280+
2281+
tween = jQuery.Tween( testObject, { "duration": 1 }, "width", 200 );
2282+
tween.run( 1 );
2283+
equal( testObject.width, 200, "Animated width" );
2284+
ok( called, "Custom jQuery.easing._default called" );
2285+
strictEqual( tween.easing, "custom",
2286+
"Animation used custom jQuery.easing._default" );
2287+
jQuery.easing._default = defaultEasing;
2288+
delete jQuery.easing.custom;
2289+
});
2290+
22362291
})();

0 commit comments

Comments
 (0)