Deferred: Always handle progress callbacks before done/fail

Fixes gh-2013
Fixes gh-2010
Closes gh-2210
This commit is contained in:
Richard Gibson
2015-04-14 13:30:58 -04:00
parent 55ac56aeda
commit 002240a6eb
2 changed files with 82 additions and 31 deletions

View File

@@ -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 );