X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=test%2Funit%2Fajax.js;h=564f692670bea15b6c1642129e11247c0021c110;hb=8356871a5522ad59cac80af2ca4695079059b97e;hp=fb328bcc75b31b14d5144d1f15175dc85cff77a5;hpb=50d78e7658382d2a2f5149cae7a6572f78ce403f;p=jquery.git diff --git a/test/unit/ajax.js b/test/unit/ajax.js index fb328bc..564f692 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -70,6 +70,44 @@ test("jQuery.ajax() - error callbacks", function() { }); }); +test("Ajax events with context", function() { + expect(6); + + stop(); + var context = {}; + + function event(e){ + equals( this, context, e.type ); + } + + function callback(){ + equals( this, context, "context is preserved on callback" ); + } + + jQuery('#foo').add(context) + .ajaxSend(event) + .ajaxComplete(event) + .ajaxError(event) + .ajaxSuccess(event); + + jQuery.ajax({ + url: url("data/name.html"), + beforeSend: callback, + success: callback, + error: callback, + complete:function(){ + callback.call(this); + setTimeout(proceed, 300); + }, + context:context + }); + + function proceed(){ + jQuery('#foo').add(context).unbind(); + start(); + } +}); + test("jQuery.ajax() - disabled globals", function() { expect( 3 ); stop(); @@ -284,19 +322,20 @@ test("pass-through request object", function() { test("ajax cache", function () { expect(18); + stop(); var count = 0; jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) { var re = /_=(.*?)(&|$)/g; - var oldOne = null; + var oldOne = null; for (var i = 0; i < 6; i++) { - var ret = re.exec(s.url); + var ret = re.exec(s.url); if (!ret) { break; } - oldOne = ret[1]; + 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"); @@ -687,9 +726,10 @@ test("jQuery.ajax() - script, Remote with scheme-less URL", function() { }); test("jQuery.getJSON(String, Hash, Function) - JSON array", function() { - expect(4); + expect(5); stop(); jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) { + ok( json.length >= 2, "Check length"); equals( json[0].name, 'John', 'Check JSON: first, name' ); equals( json[0].age, 21, 'Check JSON: first, age' ); equals( json[1].name, 'Peter', 'Check JSON: second, name' ); @@ -702,8 +742,10 @@ test("jQuery.getJSON(String, Function) - JSON object", function() { expect(2); stop(); jQuery.getJSON(url("data/json.php"), function(json) { - equals( json.data.lang, 'en', 'Check JSON: lang' ); - equals( json.data.length, 25, 'Check JSON: length' ); + if (json && json.data) { + equals( json.data.lang, 'en', 'Check JSON: lang' ); + equals( json.data.length, 25, 'Check JSON: length' ); + } start(); }); });