aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorjaubourg <j@ubourg.net>2013-02-08 16:26:36 +0100
committerDave Methvin <dave.methvin@gmail.com>2013-02-28 15:01:10 -0500
commiteebc77849cebd9a69025996939f930cbf9b1bae1 (patch)
tree87fab74faa85c7016a524ae2fe8e40ed8659509b /test
parent38bc968052f7f20af48626b6739f312224314348 (diff)
downloadjquery-eebc77849cebd9a69025996939f930cbf9b1bae1.tar.gz
jquery-eebc77849cebd9a69025996939f930cbf9b1bae1.zip
Fixes #11151, #13388. Minor refactor of response conversion and when/where
responseXXX fields are set on the jqXHR. Close gh-1164. (Cherry-picked from 69b3d5ce0f081d3f113b2917495f35df160f8522)
Diffstat (limited to 'test')
-rw-r--r--test/data/errorWithJSON.php6
-rw-r--r--test/unit/ajax.js22
2 files changed, 28 insertions, 0 deletions
diff --git a/test/data/errorWithJSON.php b/test/data/errorWithJSON.php
new file mode 100644
index 000000000..62b187ecc
--- /dev/null
+++ b/test/data/errorWithJSON.php
@@ -0,0 +1,6 @@
+<?php
+
+header("HTTP/1.0 400 Bad Request");
+header("Content-Type: application/json");
+
+echo '{ "code": 40, "message": "Bad Request" }'; \ No newline at end of file
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index e5e82f977..e2335e507 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1378,6 +1378,18 @@ module( "ajax", {
});
+ ajaxTest( "#11151 - jQuery.ajax() - parse error body", 2, {
+ url: url("data/errorWithJSON.php"),
+ dataFilter: function( string ) {
+ ok( false, "dataFilter called" );
+ return string;
+ },
+ error: function( jqXHR ) {
+ strictEqual( jqXHR.responseText, "{ \"code\": 40, \"message\": \"Bad Request\" }", "Error body properly set" );
+ deepEqual( jqXHR.responseJSON, { code: 40, message: "Bad Request" }, "Error body properly parsed" );
+ }
+ });
+
ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, {
url: url("data/1x1.jpg"),
success: function( data ) {
@@ -1477,6 +1489,16 @@ module( "ajax", {
}
});
+ ajaxTest( "#13388 - jQuery.ajax() - responseXML", 3, {
+ url: url("data/with_fries.xml"),
+ dataType: "xml",
+ success: function( resp, _, jqXHR ) {
+ notStrictEqual( resp, undefined, "XML document exists" );
+ ok( "responseXML" in jqXHR, "jqXHR.responseXML exists" );
+ strictEqual( resp, jqXHR.responseXML, "jqXHR.responseXML is set correctly" );
+ }
+ });
+
//----------- jQuery.ajaxPrefilter()
ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, {