// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise: function( obj ) {
- return typeof obj === "object" ? jQuery.extend( obj, promise ) : promise;
+ return obj != null ? jQuery.extend( obj, promise ) : promise;
}
},
deferred = {};
test("jQuery.Deferred" + withNew, function() {
- expect( 21 );
+ expect( 23 );
var defer = createDeferred();
strictEqual( value , "done" , "Passed function executed" );
});
+ createDeferred(function( defer ) {
+ var promise = defer.promise(),
+ func = function() {},
+ funcPromise = defer.promise( func );
+ strictEqual( defer.promise(), promise, "promise is always the same" );
+ strictEqual( funcPromise, func, "non objects get extended" );
+ jQuery.each( promise, function( key, value ) {
+ if ( !jQuery.isFunction( promise[ key ] ) ) {
+ ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" );
+ }
+ if ( promise[ key ] !== func[ key ] ) {
+ strictEqual( func[ key ], promise[ key ], key + " is the same" );
+ }
+ });
+ });
+
jQuery.expandedEach = jQuery.each;
jQuery.expandedEach( "resolve reject".split( " " ), function( _, change ) {
createDeferred( function( defer ) {
});
} );
+
test( "jQuery.Deferred - chainability", function() {
var defer = jQuery.Deferred();