Skip to content

Commit d5dae25

Browse files
committed
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
1 parent e06fda6 commit d5dae25

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/deferred.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ jQuery.extend( {
162162
resolve( maxDepth, deferred, Identity, special ),
163163
resolve( maxDepth, deferred, Thrower, special ),
164164
resolve( maxDepth, deferred, Identity,
165-
deferred.notify )
165+
deferred.notifyWith )
166166
);
167167
}
168168

test/unit/deferred.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,36 @@ QUnit.test( "jQuery.Deferred - notify and resolve", function( assert ) {
768768
} );
769769
} );
770770

771+
QUnit.test( "jQuery.Deferred - resolved to a notifying deferred", function( assert ) {
772+
773+
assert.expect( 2 );
774+
775+
var deferred = jQuery.Deferred(),
776+
done = assert.async( 2 );
777+
778+
deferred.resolve( jQuery.Deferred( function( notifyingDeferred ) {
779+
notifyingDeferred.notify( "foo", "bar" );
780+
notifyingDeferred.resolve( "baz", "quux" );
781+
} ) );
782+
783+
// Apply an empty then to force thenable unwrapping.
784+
// See https://github.com/jquery/jquery/issues/3000 for more info.
785+
deferred.then().then( function() {
786+
assert.deepEqual(
787+
[].slice.call( arguments ),
788+
[ "baz", "quux" ],
789+
"The fulfilled handler receives proper params"
790+
);
791+
done();
792+
}, null, function() {
793+
assert.deepEqual(
794+
[].slice.call( arguments ),
795+
[ "foo", "bar" ],
796+
"The progress handler receives proper params"
797+
);
798+
done();
799+
} );
800+
} );
771801

772802
QUnit.test( "jQuery.when(nonThenable) - like Promise.resolve", function( assert ) {
773803
"use strict";

0 commit comments

Comments
 (0)