From 35295f1c20d6f4ce724840ecad00d347ca5a1295 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Tue, 14 Apr 2015 13:30:58 -0400 Subject: Deferred: Always handle progress callbacks before done/fail Fixes gh-2013 Fixes gh-2010 Closes gh-2210 (cherry picked from commit 002240a6eb1cee2fcd886d5cf44893eb67f246f1) --- test/unit/deferred.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'test/unit') diff --git a/test/unit/deferred.js b/test/unit/deferred.js index c2dcf33d0..97f9111dd 100644 --- a/test/unit/deferred.js +++ b/test/unit/deferred.js @@ -565,6 +565,54 @@ test( "jQuery.Deferred.then - progress and thenables", function( assert ) { trigger.notify(); }); +test( "jQuery.Deferred - notify and resolve", function( assert ) { + + expect( 7 ); + + var notifiedResolved = jQuery.Deferred().notify( "foo" )/*xxx .resolve( "bar" )*/, + done = jQuery.map( new Array( 3 ), function() { return assert.async(); } ); + + notifiedResolved.progress( function( v ) { + assert.strictEqual( v, "foo", "progress value" ); + } ); + + notifiedResolved.pipe().progress( function( v ) { + assert.strictEqual( v, "foo", "piped progress value" ); + } ); + + notifiedResolved.pipe( null, null, function() { + return "baz"; + } ).progress( function( v ) { + assert.strictEqual( v, "baz", "replaced piped progress value" ); + } ); + + notifiedResolved.pipe( null, null, function() { + return jQuery.Deferred().notify( "baz" ).resolve( "quux" ); + } ).progress( function( v ) { + assert.strictEqual( v, "baz", "deferred replaced piped progress value" ); + } ); + + notifiedResolved.then().progress( function( v ) { + assert.strictEqual( v, "foo", "then'd progress value" ); + done.pop().call(); + } ); + + notifiedResolved.then( null, null, function() { + return "baz"; + } ).progress( function( v ) { + assert.strictEqual( v, "baz", "replaced then'd progress value" ); + done.pop().call(); + } ); + + notifiedResolved.then( null, null, function() { + return jQuery.Deferred().notify( "baz" ).resolve( "quux" ); + } ).progress( function( v ) { + // Progress from the surrogate deferred is ignored + assert.strictEqual( v, "quux", "deferred replaced then'd progress value" ); + done.pop().call(); + } ); +}); + test( "jQuery.when", function() { expect( 37 ); -- cgit v1.2.3