Replaces "text in-between" technique with a full-fledged one-level transitive search...
[jquery.git] / test / unit / ajax.js
index d262988..b44f077 100644 (file)
@@ -1911,9 +1911,9 @@ test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
 
 test( "jQuery.ajax - statusCode" , function() {
 
-       var count = 10;
+       var count = 12;
 
-       expect( 16 );
+       expect( 20 );
        stop();
 
        function countComplete() {
@@ -1975,7 +1975,77 @@ test( "jQuery.ajax - statusCode" , function() {
                        }
                }).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 - transitive conversions", function() {
+
+       expect( 8 );
+
+       stop();
+
+       jQuery.when(
+
+               jQuery.ajax( url("data/json.php") , {
+                       converters: {
+                               "json myjson": function( data ) {
+                                       ok( true , "converter called" );
+                                       return data;
+                               }
+                       },
+                       dataType: "myjson",
+                       success: function() {
+                               ok( true , "Transitive conversion worked" );
+                               strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text" );
+                               strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType" );
+                       }
+               }),
+
+               jQuery.ajax( url("data/json.php") , {
+                       converters: {
+                               "json myjson": function( data ) {
+                                       ok( true , "converter called (*)" );
+                                       return data;
+                               }
+                       },
+                       contents: false, /* headers are wrong so we ignore them */
+                       dataType: "* myjson",
+                       success: function() {
+                               ok( true , "Transitive conversion worked (*)" );
+                               strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text (*)" );
+                               strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType (*)" );
+                       }
+               })
+
+       ).then( start , start );
 
 });