]> source.dussan.org Git - jquery.git/commitdiff
Deferred: Fix $.when with resolved deferred and progress callbacks
authorNicolas HENRY <icewil@gmail.com>
Tue, 9 Dec 2014 12:57:15 +0000 (12:57 +0000)
committerOleg Gaidarenko <markelog@gmail.com>
Thu, 25 Dec 2014 12:39:28 +0000 (15:39 +0300)
Fixes gh-1894
Closes gh-1915

src/deferred.js
test/unit/deferred.js

index 5f6e0a2fa9dec327ec1e051187ea44fe37ed276f..939b58f37e4494553f290f4154709418d37b9d20 100644 (file)
@@ -132,9 +132,9 @@ jQuery.extend({
                        for ( ; i < length; i++ ) {
                                if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
                                        resolveValues[ i ].promise()
+                                               .progress( updateFunc( i, progressContexts, progressValues ) )
                                                .done( updateFunc( i, resolveContexts, resolveValues ) )
-                                               .fail( deferred.reject )
-                                               .progress( updateFunc( i, progressContexts, progressValues ) );
+                                               .fail( deferred.reject );
                                } else {
                                        --remaining;
                                }
index 6e4d5c44080c26ee2dee231e67040566ea868642..40f9362196306554fefb33ec09538a815b6c6031 100644 (file)
@@ -436,3 +436,25 @@ test( "jQuery.when - joined", function() {
        deferreds.futureSuccess.resolve( 1 );
        deferreds.futureError.reject( 0 );
 });
+
+test( "jQuery.when - resolved", function() {
+
+       expect( 6 );
+
+       var a = jQuery.Deferred().notify( 1 ).resolve( 4 ),
+               b = jQuery.Deferred().notify( 2 ).resolve( 5 ),
+               c = jQuery.Deferred().notify( 3 ).resolve( 6 );
+
+       jQuery.when( a, b, c ).progress(function( a, b, c ) {
+               strictEqual( a, 1, "first notify value ok" );
+               strictEqual( b, 2, "second notify value ok" );
+               strictEqual( c, 3, "third notify value ok" );
+       }).done(function( a, b, c ) {
+               strictEqual( a, 4, "first resolve value ok" );
+               strictEqual( b, 5, "second resolve value ok" );
+               strictEqual( c, 6, "third resolve value ok" );
+       }).fail(function() {
+               ok( false, "Error on resolve" );
+       });
+
+});