X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fajax.js;h=d01837239b01455de6bfe0226444c165ac2fb081;hb=5ca8f0617f5c94495380ff783452a52eab706d39;hp=1ed15b50c84bc04cf7b893827f0b63623903928c;hpb=9ab00a712fe3757f130dce8b42293c82a68c690e;p=jquery.git diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 1ed15b5..d018372 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -240,6 +240,47 @@ test("jQuery.ajax() - error callbacks", function() { }); }); +test("jQuery.ajax() - textStatus and errorThrown values", function() { + + var nb = 3; + + expect( 2 * nb ); + stop(); + + function startN() { + if ( !( --nb ) ) { + start(); + } + } + + jQuery.ajax({ + url: url("data/nonExistingURL"), + error: function( _ , textStatus , errorThrown ){ + strictEqual( textStatus, "error", "textStatus is 'error' for 404" ); + strictEqual( errorThrown, "Not Found", "errorThrown is 'Not Found' for 404"); + startN(); + } + }); + + jQuery.ajax({ + url: url("data/name.php?wait=5"), + error: function( _ , textStatus , errorThrown ){ + strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" ); + strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort"); + startN(); + } + }).abort(); + + jQuery.ajax({ + url: url("data/name.php?wait=5"), + error: function( _ , textStatus , errorThrown ){ + strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" ); + strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')"); + startN(); + } + }).abort( "mystatus" ); +}); + test("jQuery.ajax() - responseText on error", function() { expect( 1 ); @@ -2006,6 +2047,49 @@ test( "jQuery.ajax - statusCode" , function() { }); }); +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 ); + +}); + test("jQuery.ajax - active counter", function() { ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active ); });