X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fajax.js;h=c231673b3b399da09c99ff050c4938571fcec2d8;hb=06c2f06a2183ef17a8119ef25a383a02572c0b55;hp=5274b6850205cabb0f854dbc38c41bd5e270d75f;hpb=aee221d33c2db2c76639dabeca2b1e3d022e348e;p=jquery.git diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 5274b68..c231673 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -218,16 +218,26 @@ test("synchronous request with callbacks", function() { }); test("pass-through request object", function() { - expect(6); + expect(8); stop(true); var target = "data/name.html"; - var count = 0; + var successCount = 0; + var errorCount = 0; + var errorEx = ""; var success = function() { - // Re-enabled because a bug was found in the unit test that probably caused the problem - if(++count == 5) - start(); + successCount++; }; + $("#foo").ajaxError(function (e, xml, s, ex) { + errorCount++; + errorEx += ": " + xml.status; + }); + $("#foo").one('ajaxStop', function () { + equals(successCount, 5, "Check all ajax calls successful"); + equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")"); + $("#foo").unbind('ajaxError'); + start(); + }); ok( $.get(url(target), success), "get" ); ok( $.post(url(target), success), "post" ); @@ -307,6 +317,19 @@ test("load('url selector')", function() { }); }); +test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() { + expect(1); + stop(); + $.ajaxSetup({ dataType: "json" }); + $("#first").ajaxComplete(function (e, xml, s) { + equals( s.dataType, "html", "Verify the load() dataType was html" ); + $("#first").unbind("ajaxComplete"); + $.ajaxSetup({ dataType: "" }); + start(); + }); + $('#first').load("data/test3.html"); +}); + test("load(String, Function) - simple: inject text into DOM", function() { expect(2); stop(); @@ -322,15 +345,15 @@ test("load(String, Function) - check scripts", function() { window.testFoo = undefined; window.foobar = null; var verifyEvaluation = function() { - equals( foobar, "bar", 'Check if script src was evaluated after load' ); - equals( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM'); - start(); + equals( foobar, "bar", 'Check if script src was evaluated after load' ); + equals( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM'); + start(); }; $('#first').load(url('data/test.html'), function() { - ok( $('#first').html().match(/^html text/), 'Check content after loading html' ); - equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); - equals( testFoo, "foo", 'Check if script was evaluated after load' ); - setTimeout(verifyEvaluation, 600); + ok( $('#first').html().match(/^html text/), 'Check content after loading html' ); + equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); + equals( testFoo, "foo", 'Check if script was evaluated after load' ); + setTimeout(verifyEvaluation, 600); }); }); @@ -339,9 +362,9 @@ test("load(String, Function) - check file with only a script tag", function() { stop(); testFoo = undefined; $('#first').load(url('data/test2.html'), function() { - ok( $('#foo').html() == 'foo', 'Check if script evaluation has modified DOM'); - ok( testFoo == "foo", 'Check if script was evaluated after load' ); - start(); + ok( $('#foo').html() == 'foo', 'Check if script evaluation has modified DOM'); + ok( testFoo == "foo", 'Check if script was evaluated after load' ); + start(); }); }); @@ -362,6 +385,7 @@ test("$.get(String, Hash, Function) - parse xml and use text() on nodes", functi test("$.getScript(String, Function) - with callback", function() { expect(2); stop(); + window.foobar = null; $.getScript(url("data/test.js"), function() { equals( foobar, "bar", 'Check if script was evaluated' ); setTimeout(start, 100); @@ -388,6 +412,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (GET, no callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, no callback)" ); + plus(); } }); @@ -397,6 +425,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (GET, url callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, url callback)" ); + plus(); } }); @@ -407,6 +439,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (GET, data callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data callback)" ); + plus(); } }); @@ -417,6 +453,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (GET, data obj callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); } }); @@ -427,6 +467,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (POST, no callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); } }); @@ -438,6 +482,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (POST, data callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (POST, data callback)" ); + plus(); } }); @@ -449,6 +497,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (POST, data obj callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (POST, data obj callback)" ); + plus(); } }); }); @@ -469,6 +521,10 @@ test("$.ajax() - JSONP, Remote", function() { success: function(data){ ok( data.data, "JSON results returned (GET, no callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, no callback)" ); + plus(); } }); @@ -478,6 +534,10 @@ test("$.ajax() - JSONP, Remote", function() { success: function(data){ ok( data.data, "JSON results returned (GET, url callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, url callback)" ); + plus(); } }); @@ -488,6 +548,10 @@ test("$.ajax() - JSONP, Remote", function() { success: function(data){ ok( data.data, "JSON results returned (GET, data callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data callback)" ); + plus(); } }); @@ -498,6 +562,10 @@ test("$.ajax() - JSONP, Remote", function() { success: function(data){ ok( data.data, "JSON results returned (GET, data obj callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); } }); }); @@ -509,6 +577,46 @@ test("$.ajax() - script, Remote", function() { stop(); + window.foobar = null; + $.ajax({ + url: base + "data/test.js", + dataType: "script", + success: function(data){ + ok( foobar, "Script results returned (GET, no callback)" ); + start(); + } + }); +}); + +test("$.ajax() - script, Remote with POST", function() { + expect(3); + + var base = window.location.href.replace(/\?.*$/, ""); + + stop(); + + window.foobar = null; + $.ajax({ + url: base + "data/test.js", + type: "POST", + dataType: "script", + success: function(data, status){ + ok( foobar, "Script results returned (GET, no callback)" ); + equals( status, "success", "Script results returned (GET, no callback)" ); + start(); + } + }); +}); + +test("$.ajax() - script, Remote with scheme-less URL", function() { + expect(2); + + var base = window.location.href.replace(/\?.*$/, ""); + base = base.replace(/^.*?\/\//, "//"); + + stop(); + + window.foobar = null; $.ajax({ url: base + "data/test.js", dataType: "script",