Skip to content

Commit b9b5c23

Browse files
committed
Effects: add tests for jQuery.easing._default in Animation and Tween
Ref gh-2219
1 parent b7f9e62 commit b9b5c23

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
@@ -1143,49 +1143,49 @@ test( "interrupt toggle", function() {
11431143
});
11441144
}, shortDuration );
11451145
});
1146-
clock.tick(longDuration);
1147-
//FIXME untangle the set timeouts
1146+
clock.tick( longDuration );
1147+
1148+
// FIXME untangle the set timeouts
11481149
});
11491150

1150-
test("animate with per-property easing", function(){
1151+
test( "animate with per-property easing", function() {
11511152

1152-
expect(5);
1153+
expect( 5 );
11531154

1154-
var data = { a:0, b:0, c:0 },
1155-
_test1_called = false,
1156-
_test2_called = false,
1157-
_default_test_called = false,
1155+
var data = { a: 0, b: 0, c: 0 },
1156+
test1Called = false,
1157+
test2Called = false,
1158+
defaultTestCalled = false,
11581159
props = {
11591160
a: [ 100, "_test1" ],
11601161
b: [ 100, "_test2" ],
11611162
c: 100
11621163
};
11631164

1164-
jQuery.easing["_test1"] = function(p) {
1165-
_test1_called = true;
1165+
jQuery.easing._test1 = function( p ) {
1166+
test1Called = true;
11661167
return p;
11671168
};
11681169

1169-
jQuery.easing["_test2"] = function(p) {
1170-
_test2_called = true;
1170+
jQuery.easing._test2 = function( p ) {
1171+
test2Called = true;
11711172
return p;
11721173
};
11731174

1174-
jQuery.easing["_default_test"] = function(p) {
1175-
_default_test_called = true;
1175+
jQuery.easing._defaultTest = function( p ) {
1176+
defaultTestCalled = true;
11761177
return p;
11771178
};
11781179

1179-
jQuery(data).animate( props, 400, "_default_test", function(){
1180-
1181-
ok( _test1_called, "Easing function (_test1) called" );
1182-
ok( _test2_called, "Easing function (_test2) called" );
1183-
ok( _default_test_called, "Easing function (_default) called" );
1184-
equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)");
1185-
equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)");
1180+
jQuery( data ).animate( props, 400, "_defaultTest", function() {
1181+
ok( test1Called, "Easing function (_test1) called" );
1182+
ok( test2Called, "Easing function (_test2) called" );
1183+
ok( defaultTestCalled, "Easing function (_default) called" );
1184+
equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)" );
1185+
equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)" );
11861186
});
1187-
this.clock.tick( 400 );
11881187

1188+
this.clock.tick( 400 );
11891189
});
11901190

11911191
test("animate with CSS shorthand properties", function(){
@@ -2227,16 +2227,18 @@ test( "Animation should go to its end state if document.hidden = true", 1, funct
22272227
}
22282228
});
22292229

2230-
test( "jQuery.easing._default (#2218)", 2, function() {
2230+
test( "jQuery.easing._default (gh-2218)", function() {
2231+
expect( 2 );
2232+
22312233
jQuery( "#foo" )
2232-
.animate({ width: "5px" }, {
2234+
.animate( { width: "5px" }, {
22332235
duration: 5,
22342236
start: function( anim ) {
22352237
equal( anim.opts.easing, jQuery.easing._default,
22362238
"anim.opts.easing should be equal to jQuery.easing._default when the easing argument is not given" );
22372239
}
22382240
})
2239-
.animate({ height: "5px" }, {
2241+
.animate( { height: "5px" }, {
22402242
duration: 5,
22412243
easing: "linear",
22422244
start: function( anim ) {
@@ -2245,7 +2247,60 @@ test( "jQuery.easing._default (#2218)", 2, function() {
22452247
}
22462248
})
22472249
.stop();
2250+
22482251
this.clock.tick( 25 );
22492252
});
22502253

2254+
test( "jQuery.easing._default in Animation (gh-2218", function() {
2255+
expect( 3 );
2256+
2257+
var animation,
2258+
defaultEasing = jQuery.easing._default,
2259+
called = false,
2260+
testObject = { "width": 100 },
2261+
testDest = { "width": 200 };
2262+
2263+
jQuery.easing.custom = function( p ) {
2264+
called = true;
2265+
return p;
2266+
};
2267+
jQuery.easing._default = "custom";
2268+
2269+
animation = jQuery.Animation( testObject, testDest, { "duration": 1 } );
2270+
animation.done( function() {
2271+
equal( testObject.width, testDest.width, "Animated width" );
2272+
ok( called, "Custom jQuery.easing._default called" );
2273+
strictEqual( animation.opts.easing, "custom",
2274+
"Animation used custom jQuery.easing._default" );
2275+
jQuery.easing._default = defaultEasing;
2276+
delete jQuery.easing.custom;
2277+
});
2278+
2279+
this.clock.tick( 10 );
2280+
});
2281+
2282+
test( "jQuery.easing._default in Tween (gh-2218)", function() {
2283+
expect( 3 );
2284+
2285+
var tween,
2286+
defaultEasing = jQuery.easing._default,
2287+
called = false,
2288+
testObject = { "width": 100 };
2289+
2290+
jQuery.easing.custom = function( p ) {
2291+
called = true;
2292+
return p;
2293+
};
2294+
jQuery.easing._default = "custom";
2295+
2296+
tween = jQuery.Tween( testObject, { "duration": 1 }, "width", 200 );
2297+
tween.run( 1 );
2298+
equal( testObject.width, 200, "Animated width" );
2299+
ok( called, "Custom jQuery.easing._default called" );
2300+
strictEqual( tween.easing, "custom",
2301+
"Animation used custom jQuery.easing._default" );
2302+
jQuery.easing._default = defaultEasing;
2303+
delete jQuery.easing.custom;
2304+
});
2305+
22512306
})();

0 commit comments

Comments
 (0)