X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fajax.js;h=d262988eb85afa3f0223ea0200e1982a5af5b062;hb=0f6c7830ce5bdd31588dccdc40b6254fb4a9100f;hp=2e8a455ebc48d2291854ecfbf9b51e2a38ee93e9;hpb=0e93b2e24c67237c1172b5d7b1f75f52904d6a1c;p=jquery.git diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 2e8a455..d262988 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1,4 +1,4 @@ -module("ajax"); +module("ajax", { teardown: moduleTeardown }); // Safari 3 randomly crashes when running these tests, // but only in the full suite - you can run just the Ajax @@ -599,6 +599,47 @@ test("jQuery.ajax context modification", function() { equals( obj.test, "foo", "Make sure the original object is maintained." ); }); +test("jQuery.ajax context modification through ajaxSetup", function() { + expect(4); + + stop(); + + var obj = {}; + + jQuery.ajaxSetup({ + context: obj + }); + + strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." ); + + jQuery.ajax({ + url: url("data/name.html"), + complete: function() { + strictEqual( this, obj, "Make sure the original object is maintained." ); + jQuery.ajax({ + url: url("data/name.html"), + context: {}, + complete: function() { + ok( this !== obj, "Make sure overidding context is possible." ); + jQuery.ajaxSetup({ + context: false + }); + jQuery.ajax({ + url: url("data/name.html"), + beforeSend: function(){ + this.test = "foo2"; + }, + complete: function() { + ok( this !== obj, "Make sure unsetting context is possible." ); + start(); + } + }); + } + }); + } + }); +}); + test("jQuery.ajax() - disabled globals", function() { expect( 3 ); stop(); @@ -1117,10 +1158,10 @@ test("jQuery.getScript(String, Function) - no callback", function() { jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label ) { test("jQuery.ajax() - JSONP, " + label, function() { - expect(16); + expect(17); var count = 0; - function plus(){ if ( ++count == 16 ) start(); } + function plus(){ if ( ++count == 17 ) start(); } stop(); @@ -1343,15 +1384,15 @@ jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label ) jsonpCallback: "XXX", crossDomain: crossDomain, beforeSend: function() { - console.log( this.url ); + ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ) , + "The URL wasn't messed with (GET, custom callback name with no url manipulation)" ); + plus(); }, success: function(data){ - console.log(data); ok( data.data, "JSON results returned (GET, custom callback name with no url manipulation)" ); plus(); }, error: function(data){ - console.log(data); ok( false, "Ajax error JSON (GET, custom callback name with no url manipulation)" ); plus(); } @@ -1857,10 +1898,6 @@ test("jQuery ajax - atom+xml", function() { }); -test("jQuery.ajax - active counter", function() { - ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active ); -}); - test( "jQuery.ajax - Location object as url (#7531)", 1, function () { var success = false; try { @@ -1942,6 +1979,10 @@ test( "jQuery.ajax - statusCode" , function() { }); +test("jQuery.ajax - active counter", function() { + ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active ); +}); + } //} \ No newline at end of file