Skip to content

Commit

Permalink
Deferred: Propagate progress correctly from unwrapped promises
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mgol committed Jun 8, 2016
1 parent e06fda6 commit 6b3440a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/deferred.js
Expand Up @@ -162,7 +162,7 @@ jQuery.extend( {
resolve( maxDepth, deferred, Identity, special ),
resolve( maxDepth, deferred, Thrower, special ),
resolve( maxDepth, deferred, Identity,
deferred.notify )
deferred.notifyWith )
);
}

Expand Down
30 changes: 30 additions & 0 deletions test/unit/deferred.js
Expand Up @@ -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";
Expand Down

0 comments on commit 6b3440a

Please sign in to comment.