]> source.dussan.org Git - jquery.git/commitdiff
Deferred: Propagate progress correctly from unwrapped promises 3150/head
authorMichał Gołębiowski <m.goleb@gmail.com>
Wed, 8 Jun 2016 12:22:13 +0000 (14:22 +0200)
committerMichał Gołębiowski <m.goleb@gmail.com>
Thu, 9 Jun 2016 12:53:34 +0000 (14:53 +0200)
Progress parameters are now correctly propagated from a deferred to which
another deferred resolved unwrapping it.

Thanks to @gibson042 for the report and a clear description of the problem
and the needed fix.

Fixes gh-3062
Closes gh-3150

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

index 73b2f9ef2a9258df9ab2ae5b5bfffe46890ab174..a7938025ca238a1b5075ac3f4b3c0c777740be08 100644 (file)
@@ -162,7 +162,7 @@ jQuery.extend( {
                                                                                                resolve( maxDepth, deferred, Identity, special ),
                                                                                                resolve( maxDepth, deferred, Thrower, special ),
                                                                                                resolve( maxDepth, deferred, Identity,
-                                                                                                       deferred.notify )
+                                                                                                       deferred.notifyWith )
                                                                                        );
                                                                                }
 
index d8ea1918fc13122cbb6a1f32120ae714477872e8..3e147a96ee8d8b7d794b079817829463cc492788 100644 (file)
@@ -768,6 +768,36 @@ QUnit.test( "jQuery.Deferred - notify and resolve", function( assert ) {
        } );
 } );
 
+QUnit.test( "jQuery.Deferred - resolved to a notifying deferred", function( assert ) {
+
+       assert.expect( 2 );
+
+    var deferred = jQuery.Deferred(),
+               done = assert.async( 2 );
+
+       deferred.resolve( jQuery.Deferred( function( notifyingDeferred ) {
+           notifyingDeferred.notify( "foo", "bar" );
+           notifyingDeferred.resolve( "baz", "quux" );
+       } ) );
+
+       // Apply an empty then to force thenable unwrapping.
+       // See https://github.com/jquery/jquery/issues/3000 for more info.
+       deferred.then().then( function() {
+               assert.deepEqual(
+                       [].slice.call( arguments ),
+                       [ "baz", "quux" ],
+                       "The fulfilled handler receives proper params"
+               );
+               done();
+       }, null, function() {
+               assert.deepEqual(
+                       [].slice.call( arguments ),
+                       [ "foo", "bar" ],
+                       "The progress handler receives proper params"
+               );
+               done();
+       } );
+} );
 
 QUnit.test( "jQuery.when(nonThenable) - like Promise.resolve", function( assert ) {
        "use strict";