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 2a9f068
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
@@ -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.