Makes sure statusCode callbacks are ordered in the same way success and error callbacks are. Unit tests added.
This commit is contained in:
parent
64e1cdbb95
commit
9ab00a712f
2 changed files with 34 additions and 7 deletions
|
@ -427,10 +427,8 @@ jQuery.extend({
|
||||||
// Stored error
|
// Stored error
|
||||||
error,
|
error,
|
||||||
|
|
||||||
// Keep track of statusCode callbacks
|
// To keep track of statusCode based callbacks
|
||||||
oldStatusCode = statusCode;
|
oldStatusCode;
|
||||||
|
|
||||||
statusCode = undefined;
|
|
||||||
|
|
||||||
// If successful, handle type chaining
|
// If successful, handle type chaining
|
||||||
if ( status >= 200 && status < 300 || status === 304 ) {
|
if ( status >= 200 && status < 300 || status === 304 ) {
|
||||||
|
@ -588,6 +586,8 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status-dependent callbacks
|
// Status-dependent callbacks
|
||||||
|
oldStatusCode = statusCode;
|
||||||
|
statusCode = undefined;
|
||||||
jXHR.statusCode( oldStatusCode );
|
jXHR.statusCode( oldStatusCode );
|
||||||
|
|
||||||
if ( s.global ) {
|
if ( s.global ) {
|
||||||
|
|
|
@ -1911,9 +1911,9 @@ test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
|
||||||
|
|
||||||
test( "jQuery.ajax - statusCode" , function() {
|
test( "jQuery.ajax - statusCode" , function() {
|
||||||
|
|
||||||
var count = 10;
|
var count = 12;
|
||||||
|
|
||||||
expect( 16 );
|
expect( 20 );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
function countComplete() {
|
function countComplete() {
|
||||||
|
@ -1975,8 +1975,35 @@ test( "jQuery.ajax - statusCode" , function() {
|
||||||
}
|
}
|
||||||
}).statusCode( createStatusCodes( "all (immediately with method)" , isSuccess ) );
|
}).statusCode( createStatusCodes( "all (immediately with method)" , isSuccess ) );
|
||||||
|
|
||||||
});
|
var testString = "";
|
||||||
|
|
||||||
|
jQuery.ajax( url( uri ), {
|
||||||
|
success: function( a , b , jXHR ) {
|
||||||
|
ok( isSuccess , "success" );
|
||||||
|
var statusCode = {};
|
||||||
|
statusCode[ jXHR.status ] = function() {
|
||||||
|
testString += "B";
|
||||||
|
};
|
||||||
|
jXHR.statusCode( statusCode );
|
||||||
|
testString += "A";
|
||||||
|
},
|
||||||
|
error: function( jXHR ) {
|
||||||
|
ok( ! isSuccess , "error" );
|
||||||
|
var statusCode = {};
|
||||||
|
statusCode[ jXHR.status ] = function() {
|
||||||
|
testString += "B";
|
||||||
|
};
|
||||||
|
jXHR.statusCode( statusCode );
|
||||||
|
testString += "A";
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
strictEqual( testString , "AB" , "Test statusCode callbacks are ordered like " +
|
||||||
|
( isSuccess ? "success" : "error" ) + " callbacks" );
|
||||||
|
countComplete();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery.ajax - active counter", function() {
|
test("jQuery.ajax - active counter", function() {
|
||||||
|
|
Loading…
Reference in a new issue