diff options
author | jaubourg <j@ubourg.net> | 2011-01-13 17:01:25 +0100 |
---|---|---|
committer | jaubourg <j@ubourg.net> | 2011-01-13 17:01:25 +0100 |
commit | 44fc87f66ca54278e37f15885a80c2407036df57 (patch) | |
tree | 660b63f9f53bef80b9c60df7b09dfdfc27900743 /test | |
parent | 57956152d8a9d23ae97ba576b8ec4b63306c8758 (diff) | |
download | jquery-44fc87f66ca54278e37f15885a80c2407036df57.tar.gz jquery-44fc87f66ca54278e37f15885a80c2407036df57.zip |
Fixes #4964. Adds a statusCode object together with a new statusCode method on the jXHR object (deferred behaviour). They accept a map of statusCode/callback(s). Callbacks are fired when the status code of the response correponds to the key (as a success or an error callback depending on how the request completed). Unit tests added.
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/ajax.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 10c2e7183..f5b71da39 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1915,6 +1915,76 @@ test( "jQuery.ajax - Location object as url (#7531)", 1, function () { ok( success, "document.location did not generate exception" ); }); +test( "jQuery.ajax - statusCode" , function() { + + var count = 10; + + expect( 16 ); + stop(); + + function countComplete() { + if ( ! --count ) { + start(); + } + } + + function createStatusCodes( name , isSuccess ) { + name = "Test " + name + " " + ( isSuccess ? "success" : "error" ); + return { + 200: function() { + ok( isSuccess , name ); + }, + 404: function() { + ok( ! isSuccess , name ); + } + } + } + + jQuery.each( { + "data/name.html": true, + "data/someFileThatDoesNotExist.html": false + } , function( uri , isSuccess ) { + + jQuery.ajax( url( uri ) , { + statusCode: createStatusCodes( "in options" , isSuccess ), + complete: countComplete + }); + + jQuery.ajax( url( uri ) , { + complete: countComplete + }).statusCode( createStatusCodes( "immediately with method" , isSuccess ) ); + + jQuery.ajax( url( uri ) , { + complete: function(jXHR) { + jXHR.statusCode( createStatusCodes( "on complete" , isSuccess ) ); + countComplete(); + } + }); + + jQuery.ajax( url( uri ) , { + complete: function(jXHR) { + setTimeout( function() { + jXHR.statusCode( createStatusCodes( "very late binding" , isSuccess ) ); + countComplete(); + } , 100 ); + } + }); + + jQuery.ajax( url( uri ) , { + statusCode: createStatusCodes( "all (options)" , isSuccess ), + complete: function(jXHR) { + jXHR.statusCode( createStatusCodes( "all (on complete)" , isSuccess ) ); + setTimeout( function() { + jXHR.statusCode( createStatusCodes( "all (very late binding)" , isSuccess ) ); + countComplete(); + } , 100 ); + } + }).statusCode( createStatusCodes( "all (immediately with method)" , isSuccess ) ); + + }); + +}); + } //}
\ No newline at end of file |