X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fajax.js;h=9514a8edc4a818459af1d4755efac3b389d8beb5;hb=c6e88b16e9f6e45d87019db45dd04d27482d25d7;hp=15c4ed744e44621dde53623e00919e251e6147d6;hpb=0635df43914eec10e4b468ddb2f952f5024c644e;p=jquery.git diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 15c4ed7..9514a8e 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -136,6 +136,27 @@ test("$.ajax - beforeSend", function() { }); }); +test("$.ajax - beforeSend, cancel request (#2688)", function() { + expect(2); + var request = $.ajax({ + url: url("data/name.html"), + beforeSend: function() { + ok( true, "beforeSend got called, canceling" ); + return false; + }, + success: function() { + ok( false, "request didn't get canceled" ); + }, + complete: function() { + ok( false, "request didn't get canceled" ); + }, + error: function() { + ok( false, "request didn't get canceled" ); + } + }); + ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" ); +}); + var foobar; test("$.ajax - dataType html", function() { @@ -146,8 +167,8 @@ test("$.ajax - dataType html", function() { testFoo = undefined; var verifyEvaluation = function() { - ok( testFoo == "foo", 'Check if script was evaluated for datatype html' ); - ok( foobar == "bar", 'Check if script src was evaluated for datatype html' ); + equals( testFoo, "foo", 'Check if script was evaluated for datatype html' ); + equals( foobar, "bar", 'Check if script src was evaluated for datatype html' ); start(); }; @@ -277,19 +298,15 @@ test("ajax cache", function () { }); test("global ajaxSettings", function() { - expect(3); + expect(2); var tmp = jQuery.extend({}, jQuery.ajaxSettings); - var orig = { url: "data/with_fries.xml", data: null }; + var orig = { url: "data/with_fries.xml" }; var t; $.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} }); t = jQuery.extend({}, orig); - $.ajax(t); - ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending null" ); - - t = jQuery.extend({}, orig); t.data = {}; $.ajax(t); ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" ); @@ -362,8 +379,32 @@ 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' ); + equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); + equals( testFoo, "foo", 'Check if script was evaluated after load' ); + start(); + }); +}); + +test("load(String, Object, Function)", function() { + expect(2); + stop(); + + $('
').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() { + var $post = $(this).find('#post'); + equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly'); + equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly'); + start(); + }); +}); + +test("load(String, String, Function)", function() { + expect(2); + stop(); + + $('
').load(url('data/params_html.php'), 'foo=3&bar=ok', function() { + var $get = $(this).find('#get'); + equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly'); + equals( $get.find('#bar').text(), 'ok', 'Check if a of data is passed correctly'); start(); }); }); @@ -631,10 +672,10 @@ test("$.getJSON(String, Hash, Function) - JSON array", function() { expect(4); stop(); $.getJSON(url("data/json.php"), {json: "array"}, function(json) { - ok( json[0].name == 'John', 'Check JSON: first, name' ); - ok( json[0].age == 21, 'Check JSON: first, age' ); - ok( json[1].name == 'Peter', 'Check JSON: second, name' ); - ok( json[1].age == 25, 'Check JSON: second, age' ); + 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' ); + equals( json[1].age, 25, 'Check JSON: second, age' ); start(); }); }); @@ -643,8 +684,8 @@ test("$.getJSON(String, Function) - JSON object", function() { expect(2); stop(); $.getJSON(url("data/json.php"), function(json) { - ok( json.data.lang == 'en', 'Check JSON: lang' ); - ok( json.data.length == 25, 'Check JSON: length' ); + equals( json.data.lang, 'en', 'Check JSON: lang' ); + equals( json.data.length, 25, 'Check JSON: length' ); start(); }); }); @@ -656,8 +697,8 @@ test("$.getJSON(String, Function) - JSON object with absolute url to local conte stop(); $.getJSON(url(base + "data/json.php"), function(json) { - ok( json.data.lang == 'en', 'Check JSON: lang' ); - ok( json.data.length == 25, 'Check JSON: length' ); + equals( json.data.lang, 'en', 'Check JSON: lang' ); + equals( json.data.length, 25, 'Check JSON: length' ); start(); }); }); @@ -667,15 +708,15 @@ test("$.post(String, Hash, Function) - simple with xml", function() { stop(); $.post(url("data/name.php"), {xml: "5-2"}, function(xml){ $('math', xml).each(function() { - ok( $('calculation', this).text() == '5-2', 'Check for XML' ); - ok( $('result', this).text() == '3', 'Check for XML' ); + equals( $('calculation', this).text(), '5-2', 'Check for XML' ); + equals( $('result', this).text(), '3', 'Check for XML' ); }); }); $.post(url("data/name.php?xml=5-2"), {}, function(xml){ $('math', xml).each(function() { - ok( $('calculation', this).text() == '5-2', 'Check for XML' ); - ok( $('result', this).text() == '3', 'Check for XML' ); + equals( $('calculation', this).text(), '5-2', 'Check for XML' ); + equals( $('result', this).text(), '3', 'Check for XML' ); }); start(); }); @@ -744,7 +785,7 @@ test("$.ajax - simple get", function() { type: "GET", url: url("data/name.php?name=foo"), success: function(msg){ - ok( msg == 'bar', 'Check for GET' ); + equals( msg, 'bar', 'Check for GET' ); start(); } }); @@ -758,7 +799,7 @@ test("$.ajax - simple post", function() { url: url("data/name.php"), data: "name=peter", success: function(msg){ - ok( msg == 'pan', 'Check for POST' ); + equals( msg, 'pan', 'Check for POST' ); start(); } }); @@ -770,7 +811,7 @@ test("ajaxSetup()", function() { $.ajaxSetup({ url: url("data/name.php?name=foo"), success: function(msg){ - ok( msg == 'bar', 'Check for GET' ); + equals( msg, 'bar', 'Check for GET' ); start(); } }); @@ -790,6 +831,22 @@ test("custom timeout does not set error message when timeout occurs, see #970", }); }); +test("data option: evaluate function values (#2806)", function() { + stop(); + $.ajax({ + url: "data/echoQuery.php", + data: { + key: function() { + return "value"; + } + }, + success: function(result) { + equals( result, "key=value" ); + start(); + } + }) +}); + } //}