+++ /dev/null
-( function() {
-
-// Can't test what ain't there
-if ( !jQuery.fx ) {
- return;
-}
-
-var oldRaf = window.requestAnimationFrame,
- defaultPrefilter = jQuery.Animation.prefilters[ 0 ],
- defaultTweener = jQuery.Animation.tweeners[ "*" ][ 0 ],
- startTime = 505877050;
-
-// This module tests jQuery.Animation and the corresponding 1.8+ effects APIs
-QUnit.module( "animation", {
- setup: function() {
- window.requestAnimationFrame = null;
- this.sandbox = sinon.sandbox.create();
- this.clock = this.sandbox.useFakeTimers( startTime );
- this._oldInterval = jQuery.fx.interval;
- jQuery.fx.step = {};
- jQuery.fx.interval = 10;
- jQuery.now = Date.now;
- jQuery.Animation.prefilters = [ defaultPrefilter ];
- jQuery.Animation.tweeners = { "*": [ defaultTweener ] };
- },
- teardown: function() {
- this.sandbox.restore();
- jQuery.now = Date.now;
- jQuery.fx.stop();
- jQuery.fx.interval = this._oldInterval;
- window.requestAnimationFrame = oldRaf;
- return moduleTeardown.apply( this, arguments );
- }
-} );
-
-QUnit.test( "Animation( subject, props, opts ) - shape", function( assert ) {
- assert.expect( 20 );
-
- var subject = { test: 0 },
- props = { test: 1 },
- opts = { queue: "fx", duration: 100 },
- animation = jQuery.Animation( subject, props, opts );
-
- assert.equal(
- animation.elem,
- subject,
- ".elem is set to the exact object passed"
- );
- assert.equal(
- animation.originalOptions,
- opts,
- ".originalOptions is set to options passed"
- );
- assert.equal(
- animation.originalProperties,
- props,
- ".originalProperties is set to props passed"
- );
-
- assert.notEqual( animation.props, props, ".props is not the original however" );
- assert.deepEqual( animation.props, props, ".props is a copy of the original" );
-
- assert.deepEqual( animation.opts, {
- duration: 100,
- queue: "fx",
- specialEasing: { test: undefined },
- easing: jQuery.easing._default
- }, ".options is filled with default easing and specialEasing" );
-
- assert.equal( animation.startTime, startTime, "startTime was set" );
- assert.equal( animation.duration, 100, ".duration is set" );
-
- assert.equal( animation.tweens.length, 1, ".tweens has one Tween" );
- assert.equal( typeof animation.tweens[ 0 ].run, "function", "which has a .run function" );
-
- assert.equal( typeof animation.createTween, "function", ".createTween is a function" );
- assert.equal( typeof animation.stop, "function", ".stop is a function" );
-
- assert.equal( typeof animation.done, "function", ".done is a function" );
- assert.equal( typeof animation.fail, "function", ".fail is a function" );
- assert.equal( typeof animation.always, "function", ".always is a function" );
- assert.equal( typeof animation.progress, "function", ".progress is a function" );
-
- assert.equal( jQuery.timers.length, 1, "Added a timers function" );
- assert.equal( jQuery.timers[ 0 ].elem, subject, "...with .elem as the subject" );
- assert.equal( jQuery.timers[ 0 ].anim, animation, "...with .anim as the animation" );
- assert.equal( jQuery.timers[ 0 ].queue, opts.queue, "...with .queue" );
-
- // Cleanup after ourselves by ticking to the end
- this.clock.tick( 100 );
-} );
-
-QUnit.test( "Animation.prefilter( fn ) - calls prefilter after defaultPrefilter",
- function( assert ) {
- assert.expect( 1 );
-
- var prefilter = this.sandbox.stub(),
- defaultSpy = this.sandbox.spy( jQuery.Animation.prefilters, 0 );
-
- jQuery.Animation.prefilter( prefilter );
-
- jQuery.Animation( {}, {}, {} );
- assert.ok( prefilter.calledAfter( defaultSpy ), "our prefilter called after" );
- }
-);
-
-QUnit.test( "Animation.prefilter( fn, true ) - calls prefilter before defaultPrefilter",
- function( assert ) {
- assert.expect( 1 );
-
- var prefilter = this.sandbox.stub(),
- defaultSpy = this.sandbox.spy( jQuery.Animation.prefilters, 0 );
-
- jQuery.Animation.prefilter( prefilter, true );
-
- jQuery.Animation( {}, {}, {} );
- assert.ok( prefilter.calledBefore( defaultSpy ), "our prefilter called before" );
- }
-);
-
-QUnit.test( "Animation.prefilter - prefilter return hooks", function( assert ) {
- assert.expect( 34 );
-
- var animation, realAnimation, element,
- sandbox = this.sandbox,
- ourAnimation = { stop: this.sandbox.spy() },
- target = { height: 50 },
- props = { height: 100 },
- opts = { duration: 100 },
- prefilter = this.sandbox.spy( function() {
- realAnimation = this;
- sandbox.spy( realAnimation, "createTween" );
-
- assert.deepEqual( realAnimation.originalProperties, props, "originalProperties" );
- assert.equal( arguments[ 0 ], this.elem, "first param elem" );
- assert.equal( arguments[ 1 ], this.props, "second param props" );
- assert.equal( arguments[ 2 ], this.opts, "third param opts" );
- return ourAnimation;
- } ),
- defaultSpy = sandbox.spy( jQuery.Animation.prefilters, 0 ),
- queueSpy = sandbox.spy( function( next ) {
- next();
- } ),
- TweenSpy = sandbox.spy( jQuery, "Tween" );
-
- jQuery.Animation.prefilter( prefilter, true );
-
- sandbox.stub( jQuery.fx, "timer" );
-
- animation = jQuery.Animation( target, props, opts );
-
- assert.equal( prefilter.callCount, 1, "Called prefilter" );
-
- assert.equal(
- defaultSpy.callCount,
- 0,
- "Returning something from a prefilter caused remaining prefilters to not run"
- );
- assert.equal( jQuery.fx.timer.callCount, 0, "Returning something never queues a timer" );
- assert.equal(
- animation,
- ourAnimation,
- "Returning something returned it from jQuery.Animation"
- );
- assert.equal(
- realAnimation.createTween.callCount,
- 0,
- "Returning something never creates tweens"
- );
- assert.equal( TweenSpy.callCount, 0, "Returning something never creates tweens" );
-
- // Test overriden usage on queues:
- prefilter.reset();
- element = jQuery( "<div>" )
- .css( "height", 50 )
- .animate( props, 100 )
- .queue( queueSpy )
- .animate( props, 100 )
- .queue( queueSpy )
- .animate( props, 100 )
- .queue( queueSpy );
-
- assert.equal( prefilter.callCount, 1, "Called prefilter" );
- assert.equal( queueSpy.callCount, 0, "Next function in queue not called" );
-
- realAnimation.opts.complete.call( realAnimation.elem );
- assert.equal( queueSpy.callCount, 1, "Next function in queue called after complete" );
-
- assert.equal( prefilter.callCount, 2, "Called prefilter again - animation #2" );
- assert.equal( ourAnimation.stop.callCount, 0, ".stop() on our animation hasn't been called" );
-
- element.stop();
- assert.equal( ourAnimation.stop.callCount, 1, ".stop() called ourAnimation.stop()" );
- assert.ok(
- !ourAnimation.stop.args[ 0 ][ 0 ],
- ".stop( falsy ) (undefined or false are both valid)"
- );
-
- assert.equal( queueSpy.callCount, 2, "Next queue function called" );
- assert.ok( queueSpy.calledAfter( ourAnimation.stop ), "After our animation was told to stop" );
-
- // ourAnimation.stop.reset();
- assert.equal( prefilter.callCount, 3, "Got the next animation" );
-
- ourAnimation.stop.reset();
-
- // do not clear queue, gotoEnd
- element.stop( false, true );
- assert.ok( ourAnimation.stop.calledWith( true ), ".stop(true) calls .stop(true)" );
- assert.ok( queueSpy.calledAfter( ourAnimation.stop ),
- "and the next queue function ran after we were told" );
-} );
-
-QUnit.test( "Animation.tweener( fn ) - unshifts a * tweener", function( assert ) {
- assert.expect( 2 );
- var starTweeners = jQuery.Animation.tweeners[ "*" ];
-
- jQuery.Animation.tweener( jQuery.noop );
- assert.equal( starTweeners.length, 2 );
- assert.deepEqual( starTweeners, [ jQuery.noop, defaultTweener ] );
-} );
-
-QUnit.test( "Animation.tweener( 'prop', fn ) - unshifts a 'prop' tweener", function( assert ) {
- assert.expect( 4 );
- var tweeners = jQuery.Animation.tweeners,
- fn = function() {};
-
- jQuery.Animation.tweener( "prop", jQuery.noop );
- assert.equal( tweeners.prop.length, 1 );
- assert.deepEqual( tweeners.prop, [ jQuery.noop ] );
-
- jQuery.Animation.tweener( "prop", fn );
- assert.equal( tweeners.prop.length, 2 );
- assert.deepEqual( tweeners.prop, [ fn, jQuery.noop ] );
-} );
-
-QUnit.test(
- "Animation.tweener( 'list of props', fn ) - unshifts a tweener to each prop",
- function( assert ) {
- assert.expect( 2 );
- var tweeners = jQuery.Animation.tweeners,
- fn = function() {};
-
- jQuery.Animation.tweener( "list of props", jQuery.noop );
- assert.deepEqual( tweeners, {
- list: [ jQuery.noop ],
- of: [ jQuery.noop ],
- props: [ jQuery.noop ],
- "*": [ defaultTweener ]
- } );
-
- // Test with extra whitespaces
- jQuery.Animation.tweener( " list\t of \tprops\n*", fn );
- assert.deepEqual( tweeners, {
- list: [ fn, jQuery.noop ],
- of: [ fn, jQuery.noop ],
- props: [ fn, jQuery.noop ],
- "*": [ fn, defaultTweener ]
- } );
- }
-);
-
-} )();
+++ /dev/null
-( function() {
-
-// Can't test what ain't there
-if ( !jQuery.fx ) {
- return;
-}
-
-var oldRaf = window.requestAnimationFrame;
-
-QUnit.module( "tween", {
- setup: function() {
- window.requestAnimationFrame = null;
- this.sandbox = sinon.sandbox.create();
- this.clock = this.sandbox.useFakeTimers( 505877050 );
- this._oldInterval = jQuery.fx.interval;
- jQuery.fx.step = {};
- jQuery.fx.interval = 10;
- jQuery.now = Date.now;
- },
- teardown: function() {
- this.sandbox.restore();
- jQuery.now = Date.now;
- jQuery.fx.stop();
- jQuery.fx.interval = this._oldInterval;
- window.requestAnimationFrame = oldRaf;
- return moduleTeardown.apply( this, arguments );
- }
-} );
-
-QUnit.test( "jQuery.Tween - Default propHooks on plain objects", function( assert ) {
- assert.expect( 8 );
- var propHooks, defaultHook, testObject, fakeTween, stepSpy;
-
- propHooks = jQuery.Tween.propHooks;
- assert.equal( typeof propHooks, "object", "jQuery.Tween.propHooks exists" );
-
- defaultHook = propHooks._default;
- assert.ok( defaultHook, "_default propHook exists" );
-
- testObject = { test: 0 };
- fakeTween = { elem: testObject, prop: "test", now: 10, unit: "px" };
-
- assert.equal( defaultHook.get( fakeTween ), 0, "Can get property of object" );
-
- fakeTween.prop = "testMissing";
- assert.equal( defaultHook.get( fakeTween ), undefined, "Can get missing property on object" );
-
- defaultHook.set( fakeTween );
- assert.equal( testObject.testMissing, 10, "Sets missing value properly on plain object" );
-
- fakeTween.prop = "opacity";
- defaultHook.set( fakeTween );
- assert.equal( testObject.opacity, 10, "Correctly set opacity on plain object" );
-
- fakeTween.prop = "test";
- stepSpy = jQuery.fx.step.test = this.sandbox.spy();
-
- defaultHook.set( fakeTween );
- assert.ok( stepSpy.calledWith( fakeTween ), "Step function called with Tween" );
- assert.equal( testObject.test, 0, "Because step didn't set, value is unchanged" );
-} );
-
-QUnit.test( "jQuery.Tween - Default propHooks on elements", function( assert ) {
- assert.expect( 19 );
- var propHooks, defaultHook, testElement, fakeTween, cssStub, styleStub, stepSpy;
-
- propHooks = jQuery.Tween.propHooks;
- assert.equal( typeof propHooks, "object", "jQuery.Tween.propHooks exists" );
-
- defaultHook = propHooks._default;
- assert.ok( defaultHook, "_default propHook exists" );
-
- testElement = jQuery( "<div>" )[ 0 ];
- fakeTween = { elem: testElement, prop: "height", now: 10, unit: "px" };
-
- cssStub = this.sandbox.stub( jQuery, "css" ).returns( 10 );
-
- assert.equal( defaultHook.get( fakeTween ), 10, "Gets expected style value" );
- assert.ok( cssStub.calledWith( testElement, "height", "" ), "Calls jQuery.css correctly" );
-
- fakeTween.prop = "testOpti";
- testElement.testOpti = 15;
- cssStub.reset();
-
- assert.equal( defaultHook.get( fakeTween ), 15, "Gets expected value not defined on style" );
- assert.equal( cssStub.callCount, 0, "Did not call jQuery.css" );
-
- fakeTween.prop = "testMissing";
- assert.equal( defaultHook.get( fakeTween ), 10, "Can get missing property on element" );
- assert.ok( cssStub.calledWith( testElement, "testMissing", "" ), "...using jQuery.css" );
-
- cssStub.returns( "" );
- assert.equal( defaultHook.get( fakeTween ), 0, "Uses 0 for empty string" );
-
- cssStub.returns( "auto" );
- assert.equal( defaultHook.get( fakeTween ), 0, "Uses 0 for 'auto'" );
-
- cssStub.returns( null );
- assert.equal( defaultHook.get( fakeTween ), 0, "Uses 0 for null" );
-
- cssStub.returns( undefined );
- assert.equal( defaultHook.get( fakeTween ), 0, "Uses 0 for undefined" );
-
- cssStub.reset();
-
- // Setters
- styleStub = this.sandbox.stub( jQuery, "style" );
- fakeTween.prop = "height";
-
- defaultHook.set( fakeTween );
- assert.ok( styleStub.calledWith( testElement, "height", "10px" ),
- "Calls jQuery.style with elem, prop, now+unit" );
-
- styleStub.reset();
- fakeTween.prop = "testMissing";
-
- defaultHook.set( fakeTween );
- assert.equal( styleStub.callCount, 0, "Did not call jQuery.style for non css property" );
- assert.equal( testElement.testMissing, 10, "Instead, set value on element directly" );
-
- jQuery.cssHooks.testMissing = jQuery.noop;
- fakeTween.now = 11;
-
- defaultHook.set( fakeTween );
- delete jQuery.cssHooks.testMissing;
-
- assert.ok( styleStub.calledWith( testElement, "testMissing", "11px" ),
- "Presence of cssHooks causes jQuery.style with elem, prop, now+unit" );
- assert.equal( testElement.testMissing, 10, "And value was unchanged" );
-
- stepSpy = jQuery.fx.step.test = this.sandbox.spy();
- styleStub.reset();
-
- fakeTween.prop = "test";
- defaultHook.set( fakeTween );
- assert.ok( stepSpy.calledWith( fakeTween ), "Step function called with Tween" );
- assert.equal( styleStub.callCount, 0, "Did not call jQuery.style" );
-} );
-
-QUnit.test( "jQuery.Tween - Plain Object", function( assert ) {
- assert.expect( 13 );
- var testObject = { test: 100 },
- testOptions = { duration: 100 },
- tween, easingSpy;
-
- tween = jQuery.Tween( testObject, testOptions, "test", 0, "linear" );
- assert.equal( tween.elem, testObject, "Sets .element" );
- assert.equal( tween.options, testOptions, "sets .options" );
- assert.equal( tween.prop, "test", "sets .prop" );
- assert.equal( tween.end, 0, "sets .end" );
-
- assert.equal( tween.easing, "linear", "sets .easing when provided" );
-
- assert.equal( tween.start, 100, "Reads .start value during construction" );
- assert.equal( tween.now, 100, "Reads .now value during construction" );
-
- easingSpy = this.sandbox.spy( jQuery.easing, "linear" );
-
- assert.equal( tween.run( 0.1 ), tween, ".run() returns this" );
-
- assert.equal( tween.now, 90, "Calculated tween" );
-
- assert.ok( easingSpy.calledWith( 0.1, 0.1 * testOptions.duration, 0, 1, testOptions.duration ),
- "...using jQuery.easing.linear with back-compat arguments" );
- assert.equal( testObject.test, 90, "Set value" );
-
- tween.run( 1 );
- assert.equal( testObject.test, 0, "Checking another value" );
-
- tween.run( 0 );
- assert.equal( testObject.test, 100, "Can even go back in time" );
-} );
-
-QUnit.test( "jQuery.Tween - Element", function( assert ) {
- assert.expect( 15 );
- var testElement = jQuery( "<div>" ).css( "height", 100 )[ 0 ],
- testOptions = { duration: 100 },
- tween, easingSpy, eased;
-
- tween = jQuery.Tween( testElement, testOptions, "height", 0 );
- assert.equal( tween.elem, testElement, "Sets .element" );
- assert.equal( tween.options, testOptions, "sets .options" );
- assert.equal( tween.prop, "height", "sets .prop" );
- assert.equal( tween.end, 0, "sets .end" );
-
- assert.equal(
- tween.easing,
- jQuery.easing._default,
- "sets .easing to default when not provided"
- );
- assert.equal( tween.unit, "px", "sets .unit to px when not provided" );
-
- assert.equal( tween.start, 100, "Reads .start value during construction" );
- assert.equal( tween.now, 100, "Reads .now value during construction" );
-
- easingSpy = this.sandbox.spy( jQuery.easing, "swing" );
-
- assert.equal( tween.run( 0.1 ), tween, ".run() returns this" );
- assert.equal( tween.pos, jQuery.easing.swing( 0.1 ), "set .pos" );
- eased = 100 - ( jQuery.easing.swing( 0.1 ) * 100 );
- assert.equal( tween.now, eased, "Calculated tween" );
-
- assert.ok(
- easingSpy.calledWith( 0.1, 0.1 * testOptions.duration, 0, 1, testOptions.duration ),
- "...using jQuery.easing.linear with back-compat arguments"
- );
- assert.equal(
- parseFloat( testElement.style.height ).toFixed( 2 ),
- eased.toFixed( 2 ), "Set value"
- );
-
- tween.run( 1 );
- assert.equal( testElement.style.height, "0px", "Checking another value" );
-
- tween.run( 0 );
- assert.equal( testElement.style.height, "100px", "Can even go back in time" );
-} );
-
-QUnit.test( "jQuery.Tween - No duration", function( assert ) {
- assert.expect( 3 );
-
- var testObject = { test: 100 },
- testOptions = { duration: 0 },
- tween, easingSpy;
-
- tween = jQuery.Tween( testObject, testOptions, "test", 0 );
- easingSpy = this.sandbox.spy( jQuery.easing, "swing" );
- tween.run( 0.5 );
-
- assert.equal( tween.pos, 0.5, "set .pos correctly" );
- assert.equal( testObject.test, 50, "set value on object correctly" );
- assert.equal( easingSpy.callCount, 0, "didn't ease the value" );
-} );
-
-QUnit.test( "jQuery.Tween - step function option", function( assert ) {
- assert.expect( 4 );
-
- var testObject = { test: 100 },
- testOptions = { duration: 100, step: this.sandbox.spy() },
- tween, propHookSpy;
-
- propHookSpy = this.sandbox.spy( jQuery.Tween.propHooks._default, "set" );
-
- tween = jQuery.Tween( testObject, testOptions, "test", 0, "linear" );
- assert.equal( testOptions.step.callCount, 0, "didn't call step on create" );
-
- tween.run( 0.5 );
- assert.ok(
- testOptions.step.calledOn( testObject ),
- "Called step function in context of animated object"
- );
- assert.ok(
- testOptions.step.calledWith( 50, tween ),
- "Called step function with correct parameters"
- );
- assert.ok(
- testOptions.step.calledBefore( propHookSpy ),
- "Called step function before calling propHook.set"
- );
-
-} );
-
-QUnit.test( "jQuery.Tween - custom propHooks", function( assert ) {
- assert.expect( 3 );
-
- var testObject = {},
- testOptions = { duration: 100, step: this.sandbox.spy() },
- propHook = {
- get: sinon.stub().returns( 100 ),
- set: sinon.stub()
- },
- tween;
-
- jQuery.Tween.propHooks.testHooked = propHook;
-
- tween = jQuery.Tween( testObject, testOptions, "testHooked", 0, "linear" );
- assert.ok( propHook.get.calledWith( tween ), "called propHook.get on create" );
- assert.equal( tween.now, 100, "Used return value from propHook.get" );
-
- tween.run( 0.5 );
- assert.ok(
- propHook.set.calledWith( tween ),
- "Called propHook.set function with correct parameters"
- );
-
- delete jQuery.Tween.propHooks.testHooked;
-} );
-
-QUnit.test( "jQuery.Tween - custom propHooks - advanced values", function( assert ) {
- assert.expect( 5 );
-
- var testObject = {},
- testOptions = { duration: 100, step: this.sandbox.spy() },
- propHook = {
- get: sinon.stub().returns( [ 0, 0 ] ),
- set: sinon.spy()
- },
- tween;
-
- jQuery.Tween.propHooks.testHooked = propHook;
-
- tween = jQuery.Tween( testObject, testOptions, "testHooked", [ 1, 1 ], "linear" );
- assert.ok( propHook.get.calledWith( tween ), "called propHook.get on create" );
- assert.deepEqual( tween.start, [ 0, 0 ], "Used return value from get" );
-
- tween.run( 0.5 );
-
- // Some day this NaN assumption might change - perhaps add a "calc" helper to the hooks?
- assert.ok( isNaN( tween.now ), "Used return value from propHook.get" );
- assert.equal( tween.pos, 0.5, "But the eased percent is still available" );
- assert.ok(
- propHook.set.calledWith( tween ),
- "Called propHook.set function with correct parameters"
- );
-
- delete jQuery.Tween.propHooks.testHooked;
-} );
-
-} )();