X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=test%2Funit%2Fajax.js;h=84d35188db640837275546abf2b2a41ac5b81695;hb=be4a8c32ac77c3b1cdf1b598943b23bdb3119467;hp=2b3cfb656a47b5cb25e6b8beb1ea0814bc09c162;hpb=701b072e1a104bce03df700c5f620d4000ccd573;p=jquery.git diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 2b3cfb6..84d3518 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" ); @@ -236,6 +246,36 @@ test("pass-through request object", function() { ok( $.ajax({url: url(target), success: success}), "generic" ); }); +test("ajax cache", function () { + expect(18); + stop(); + + var count = 0; + + $("#firstp").bind("ajaxSuccess", function (e, xml, s) { + var re = /_=(.*?)(&|$)/g; + var oldOne = null; + for (var i = 0; i < 6; i++) { + var ret = re.exec(s.url); + if (!ret) { + break; + } + oldOne = ret[1]; + } + equals(i, 1, "Test to make sure only one 'no-cache' parameter is there"); + ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced"); + if(++count == 6) + start(); + }); + + ok( $.ajax({url: "data/text.php", cache:false}), "test with no parameters" ); + ok( $.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" ); + ok( $.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" ); + ok( $.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" ); + ok( $.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" ); + ok( $.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" ); +}); + test("global ajaxSettings", function() { expect(3);