aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Gołębiowski <m.goleb@gmail.com>2016-06-08 14:22:13 +0200
committerMichał Gołębiowski <m.goleb@gmail.com>2016-06-09 14:53:34 +0200
commitd5dae259eb52a838f94703d51999f63deec19bfd (patch)
tree396cb13db52315e6818e787166c42ed49270b9d2
parente06fda69f00082b44fd39ce8e851f72d29999011 (diff)
downloadjquery-d5dae259eb52a838f94703d51999f63deec19bfd.tar.gz
jquery-d5dae259eb52a838f94703d51999f63deec19bfd.zip
Deferred: Propagate progress correctly from unwrapped promises
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
-rw-r--r--src/deferred.js2
-rw-r--r--test/unit/deferred.js30
2 files changed, 31 insertions, 1 deletions
diff --git a/src/deferred.js b/src/deferred.js
index 73b2f9ef2..a7938025c 100644
--- a/src/deferred.js
+++ b/src/deferred.js
@@ -162,7 +162,7 @@ jQuery.extend( {
resolve( maxDepth, deferred, Identity, special ),
resolve( maxDepth, deferred, Thrower, special ),
resolve( maxDepth, deferred, Identity,
- deferred.notify )
+ deferred.notifyWith )
);
}
diff --git a/test/unit/deferred.js b/test/unit/deferred.js
index d8ea1918f..3e147a96e 100644
--- a/test/unit/deferred.js
+++ b/test/unit/deferred.js
@@ -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";