Skip to content
Permalink
Browse files

Have Deferred.always return the object onto which it is currently att…

…ached to enable true chainability. Fixes #10723. Unit tests added.
  • Loading branch information...
jaubourg committed Nov 9, 2011
1 parent c3600e2 commit 2a9f0681dee3a6421bafd2fbc4451c9fe364b6ca
Showing with 15 additions and 1 deletion.
  1. +2 −1 src/deferred.js
  2. +13 −0 test/unit/deferred.js
@@ -33,7 +33,8 @@ jQuery.extend({
return this;
},
always: function() {
return deferred.done.apply( deferred, arguments ).fail.apply( deferred, arguments );
deferred.done.apply( deferred, arguments ).fail.apply( deferred, arguments );
return this;
},
pipe: function( fnDone, fnFail, fnProgress ) {
return jQuery.Deferred(function( newDefer ) {
@@ -56,6 +56,19 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
});
} );

test( "jQuery.Deferred - chainability", function() {

var methods = "resolve reject notify resolveWith rejectWith notifyWith done fail progress then always".split( " " ),
defer = jQuery.Deferred();

expect( methods.length );

jQuery.each( methods, function( _, method ) {
var object = { m: defer[ method ] };
strictEqual( object.m(), object, method + " is chainable" );
});
});

test( "jQuery.Deferred.pipe - filtering (done)", function() {

expect(4);

0 comments on commit 2a9f068

Please sign in to comment.
You can’t perform that action at this time.