diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2015-11-16 15:36:48 -0500 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2015-11-17 15:11:46 -0500 |
commit | cb80b42b91bc7d0e75fb842f733878b848a8b9c1 (patch) | |
tree | 5717a0474510e6f34eebdcc1d3b8ab8b86eb21dc | |
parent | cf7102c3f1bcbd135f24947a3a3216cff272bdc2 (diff) | |
download | jquery-cb80b42b91bc7d0e75fb842f733878b848a8b9c1.tar.gz jquery-cb80b42b91bc7d0e75fb842f733878b848a8b9c1.zip |
Effects: add tests for using jQuery.speed directly
Fixes gh-2716
Close gh-2724
-rw-r--r-- | test/unit/effects.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/test/unit/effects.js b/test/unit/effects.js index 0f38f81a5..33357deda 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -2495,4 +2495,89 @@ QUnit.test( "Show/hide/toggle and display: inline", function( assert ) { } ); } ); +function testEasing( assert, speed, easing, complete ) { + assert.expect( 4 ); + var options = jQuery.speed( speed, easing, complete ); + + assert.equal( options.duration, 10, "Duration set properly" ); + assert.equal( + jQuery.isFunction( options.easing ) ? options.easing() : options.easing, + "linear", + "Easing set properly" + ); + assert.equal( options.queue, "fx", "Queue defaults to fx" ); + options.complete(); +} + +QUnit.test( "jQuery.speed( speed, easing, complete )", function( assert ) { + testEasing( assert, 10, "linear", function() { + assert.ok( true, "Complete called" ); + } ); +} ); + +QUnit.test( "jQuery.speed( speed, easing, complete ) - with easing function", function( assert ) { + testEasing( + assert, + 10, + function() { + return "linear"; + }, + function() { + assert.ok( true, "Complete called" ); + } + ); +} ); + +QUnit.test( "jQuery.speed( options )", function( assert ) { + testEasing( assert, { + duration: 10, + easing: "linear", + complete: function() { + assert.ok( true, "Complete called" ); + } + } ); +} ); + +QUnit.test( "jQuery.speed( options ) - with easing function", function( assert ) { + testEasing( assert, { + duration: 10, + easing: function() { + return "linear"; + }, + complete: function() { + assert.ok( true, "Complete called" ); + } + } ); +} ); + +QUnit.test( "jQuery.speed( options ) - queue values", function( assert ) { + assert.expect( 5 ); + + var get = function( queue ) { + return jQuery.speed( { queue: queue } ).queue; + }; + + assert.equal( get( null ), "fx", "null defaults to 'fx'" ); + assert.equal( get( undefined ), "fx", "undefined defaults to 'fx'" ); + assert.equal( get( true ), "fx", "true defaults to 'fx'" ); + assert.equal( get( "fx" ), "fx", "'fx' passed through" ); + assert.equal( get( "custom" ), "custom", "'custom' passed through" ); +} ); + +QUnit.test( "jQuery.speed() - durations", function( assert ) { + assert.expect( 5 ); + + var get = function( duration ) { + return jQuery.speed( duration ).duration; + }; + + assert.equal( get( 100 ), 100, "jQuery.speed sets number duration" ); + assert.equal( get(), jQuery.fx.speeds._default, "jQuery.speed falls back default duration" ); + assert.equal( get( "slow" ), jQuery.fx.speeds.slow, "jQuery.speed uses preset speeds" ); + assert.equal( get( "fast" ), jQuery.fx.speeds.fast, "jQuery.speed uses preset speeds" ); + jQuery.fx.off = true; + assert.equal( get( 100 ), 0, "jQuery.speed defaults duration to zero if fx is off" ); + jQuery.fx.off = false; +} ); + } )(); |