mirror of
https://github.com/jquery/jquery.git
synced 2026-04-20 03:01:22 -04:00
Propagate context of returned deferred object in Deferred.then(). Fixes #13160.
This commit is contained in:
@@ -273,7 +273,7 @@ test( "jQuery.Deferred.then - deferred (progress)", function() {
|
||||
|
||||
test( "jQuery.Deferred.then - context", function() {
|
||||
|
||||
expect( 4 );
|
||||
expect( 7 );
|
||||
|
||||
var context = {};
|
||||
|
||||
@@ -284,6 +284,12 @@ test( "jQuery.Deferred.then - context", function() {
|
||||
strictEqual( value, 6, "proper value received" );
|
||||
});
|
||||
|
||||
jQuery.Deferred().resolve().then(function() {
|
||||
return jQuery.Deferred().resolveWith(context);
|
||||
}).done(function() {
|
||||
strictEqual( this, context, "custom context of returned deferred correctly propagated" );
|
||||
});
|
||||
|
||||
var defer = jQuery.Deferred(),
|
||||
piped = defer.then(function( value ) {
|
||||
return value * 3;
|
||||
@@ -295,6 +301,16 @@ test( "jQuery.Deferred.then - context", function() {
|
||||
strictEqual( this, piped, "default context gets updated to latest promise in the chain" );
|
||||
strictEqual( value, 6, "proper value received" );
|
||||
});
|
||||
|
||||
var defer2 = jQuery.Deferred(),
|
||||
piped2 = defer2.then();
|
||||
|
||||
defer2.resolve( 2 );
|
||||
|
||||
piped2.done(function( value ) {
|
||||
strictEqual( this, piped2, "default context gets updated to latest promise in the chain (without passing function)" );
|
||||
strictEqual( value, 2, "proper value received (without passing function)" );
|
||||
});
|
||||
});
|
||||
|
||||
test( "jQuery.when", function() {
|
||||
|
||||
Reference in New Issue
Block a user