diff options
author | jaubourg <j@ubourg.net> | 2012-04-03 14:19:27 +0200 |
---|---|---|
committer | jaubourg <j@ubourg.net> | 2012-04-03 14:19:27 +0200 |
commit | 03c5836fa1832e55971dc1d66b461651952009dc (patch) | |
tree | 17f913602ede8e94c9483e16552489b9f56059b0 /test | |
parent | 914df9cb42219200a0286d15e0f45a9994b8ab3d (diff) | |
parent | a41f2406748e3113751ab1e5b5d990d9144123fc (diff) | |
download | jquery-03c5836fa1832e55971dc1d66b461651952009dc.tar.gz jquery-03c5836fa1832e55971dc1d66b461651952009dc.zip |
Merge branch '1.8/#11010/Deferred' into 1.8pre
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/deferred.js | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/test/unit/deferred.js b/test/unit/deferred.js index 4a50da2c1..7ff274d56 100644 --- a/test/unit/deferred.js +++ b/test/unit/deferred.js @@ -8,32 +8,36 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) { test("jQuery.Deferred" + withNew, function() { - expect( 22 ); + expect( 23 ); - createDeferred().resolve().then( function() { + var defer = createDeferred(); + + strictEqual( defer.pipe, defer.then, "pipe is an alias of then" ); + + createDeferred().resolve().done(function() { ok( true , "Success on resolve" ); ok( this.isResolved(), "Deferred is resolved" ); strictEqual( this.state(), "resolved", "Deferred is resolved (state)" ); - }, function() { + }).fail(function() { ok( false , "Error on resolve" ); - }).always( function() { + }).always(function() { ok( true , "Always callback on resolve" ); }); - createDeferred().reject().then( function() { + createDeferred().reject().done(function() { ok( false , "Success on reject" ); - }, function() { + }).fail(function() { ok( true , "Error on reject" ); ok( this.isRejected(), "Deferred is rejected" ); strictEqual( this.state(), "rejected", "Deferred is rejected (state)" ); - }).always( function() { + }).always(function() { ok( true , "Always callback on reject" ); }); - createDeferred( function( defer ) { + createDeferred(function( defer ) { ok( this === defer , "Defer passed as this & first argument" ); this.resolve( "done" ); - }).then( function( value ) { + }).done( function( value ) { strictEqual( value , "done" , "Passed function executed" ); }); @@ -58,7 +62,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) { test( "jQuery.Deferred - chainability", function() { - var methods = "resolve reject notify resolveWith rejectWith notifyWith done fail progress then always".split( " " ), + var methods = "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split( " " ), defer = jQuery.Deferred(); expect( methods.length ); @@ -69,12 +73,12 @@ test( "jQuery.Deferred - chainability", function() { }); }); -test( "jQuery.Deferred.pipe - filtering (done)", function() { +test( "jQuery.Deferred.then - filtering (done)", function() { expect(4); var defer = jQuery.Deferred(), - piped = defer.pipe(function( a, b ) { + piped = defer.then(function( a, b ) { return a * b; }), value1, @@ -96,21 +100,21 @@ test( "jQuery.Deferred.pipe - filtering (done)", function() { strictEqual( value2, 3, "second resolve value ok" ); strictEqual( value3, 6, "result of filter ok" ); - jQuery.Deferred().reject().pipe(function() { - ok( false, "pipe should not be called on reject" ); + jQuery.Deferred().reject().then(function() { + ok( false, "then should not be called on reject" ); }); - jQuery.Deferred().resolve().pipe( jQuery.noop ).done(function( value ) { - strictEqual( value, undefined, "pipe done callback can return undefined/null" ); + jQuery.Deferred().resolve().then( jQuery.noop ).done(function( value ) { + strictEqual( value, undefined, "then done callback can return undefined/null" ); }); }); -test( "jQuery.Deferred.pipe - filtering (fail)", function() { +test( "jQuery.Deferred.then - filtering (fail)", function() { expect(4); var defer = jQuery.Deferred(), - piped = defer.pipe( null, function( a, b ) { + piped = defer.then( null, function( a, b ) { return a * b; } ), value1, @@ -132,21 +136,21 @@ test( "jQuery.Deferred.pipe - filtering (fail)", function() { strictEqual( value2, 3, "second reject value ok" ); strictEqual( value3, 6, "result of filter ok" ); - jQuery.Deferred().resolve().pipe( null, function() { - ok( false, "pipe should not be called on resolve" ); + jQuery.Deferred().resolve().then( null, function() { + ok( false, "then should not be called on resolve" ); } ); - jQuery.Deferred().reject().pipe( null, jQuery.noop ).fail(function( value ) { - strictEqual( value, undefined, "pipe fail callback can return undefined/null" ); + jQuery.Deferred().reject().then( null, jQuery.noop ).fail(function( value ) { + strictEqual( value, undefined, "then fail callback can return undefined/null" ); }); }); -test( "jQuery.Deferred.pipe - filtering (progress)", function() { +test( "jQuery.Deferred.then - filtering (progress)", function() { expect(3); var defer = jQuery.Deferred(), - piped = defer.pipe( null, null, function( a, b ) { + piped = defer.then( null, null, function( a, b ) { return a * b; } ), value1, @@ -169,12 +173,12 @@ test( "jQuery.Deferred.pipe - filtering (progress)", function() { strictEqual( value3, 6, "result of filter ok" ); }); -test( "jQuery.Deferred.pipe - deferred (done)", function() { +test( "jQuery.Deferred.then - deferred (done)", function() { expect(3); var defer = jQuery.Deferred(), - piped = defer.pipe(function( a, b ) { + piped = defer.then(function( a, b ) { return jQuery.Deferred(function( defer ) { defer.reject( a * b ); }); @@ -199,12 +203,12 @@ test( "jQuery.Deferred.pipe - deferred (done)", function() { strictEqual( value3, 6, "result of filter ok" ); }); -test( "jQuery.Deferred.pipe - deferred (fail)", function() { +test( "jQuery.Deferred.then - deferred (fail)", function() { expect(3); var defer = jQuery.Deferred(), - piped = defer.pipe( null, function( a, b ) { + piped = defer.then( null, function( a, b ) { return jQuery.Deferred(function( defer ) { defer.resolve( a * b ); }); @@ -229,12 +233,12 @@ test( "jQuery.Deferred.pipe - deferred (fail)", function() { strictEqual( value3, 6, "result of filter ok" ); }); -test( "jQuery.Deferred.pipe - deferred (progress)", function() { +test( "jQuery.Deferred.then - deferred (progress)", function() { expect(3); var defer = jQuery.Deferred(), - piped = defer.pipe( null, null, function( a, b ) { + piped = defer.then( null, null, function( a, b ) { return jQuery.Deferred(function( defer ) { defer.resolve( a * b ); }); @@ -259,13 +263,13 @@ test( "jQuery.Deferred.pipe - deferred (progress)", function() { strictEqual( value3, 6, "result of filter ok" ); }); -test( "jQuery.Deferred.pipe - context", function() { +test( "jQuery.Deferred.then - context", function() { expect(4); var context = {}; - jQuery.Deferred().resolveWith( context, [ 2 ] ).pipe(function( value ) { + jQuery.Deferred().resolveWith( context, [ 2 ] ).then(function( value ) { return value * 3; }).done(function( value ) { strictEqual( this, context, "custom context correctly propagated" ); @@ -273,7 +277,7 @@ test( "jQuery.Deferred.pipe - context", function() { }); var defer = jQuery.Deferred(), - piped = defer.pipe(function( value ) { + piped = defer.then(function( value ) { return value * 3; }); |