aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2025-03-31 18:09:35 +0200
committerGitHub <noreply@github.com>2025-03-31 18:09:35 +0200
commit76687566f0569dc832f13e901f0d2ce74016cd4d (patch)
tree7cda6eae2f20af3a64211678e55ceea0204448c4
parent50ca957192e891afe37a7080a7c6c08ad1d469e7 (diff)
downloadjquery-76687566f0569dc832f13e901f0d2ce74016cd4d.tar.gz
jquery-76687566f0569dc832f13e901f0d2ce74016cd4d.zip
Tests: Add tests for `jQuery.get( String, null-ish, null-ish, String )`
Also, fix `mock.php` formatting to not fail the `jQuery.get( String, null, String )` test in PHP mode. Closes gh-5640 Ref gh-4989 Ref jquery/api.jquery.com#1208
-rw-r--r--test/data/mock.php4
-rw-r--r--test/unit/ajax.js33
2 files changed, 34 insertions, 3 deletions
diff --git a/test/data/mock.php b/test/data/mock.php
index 105f9867b..013189521 100644
--- a/test/data/mock.php
+++ b/test/data/mock.php
@@ -95,9 +95,9 @@ QUnit.assert.ok( true, "mock executed");';
}
if ( isset( $req->query['array'] ) ) {
- echo '[ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ]';
+ echo '[{"name":"John","age":21},{"name":"Peter","age":25}]';
} else {
- echo '{ "data": {"lang": "en", "length": 25} }';
+ echo '{"data":{"lang":"en","length":25}}';
}
}
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 53dc9c5d2..253272499 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -2782,7 +2782,7 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
} );
- QUnit.test( "jQuery.get( String, null-ish, String ) - dataType with null callback (gh-4989)",
+ QUnit.test( "jQuery.get( String, null, String ) - dataType with null callback (gh-4989)",
function( assert ) {
assert.expect( 2 );
var done = assert.async( 2 );
@@ -2802,6 +2802,37 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
} );
+ QUnit.test( "jQuery.get( String, null-ish, null-ish, String ) - dataType with null/undefined data & callback",
+ function( assert ) {
+ assert.expect( 8 );
+ var done = assert.async( 8 );
+
+ [
+ { data: null, success: null },
+ { data: null, success: undefined },
+ { data: undefined, success: null },
+ { data: undefined, success: undefined }
+ ].forEach( function( options ) {
+ var data = options.data,
+ success = options.success;
+ jQuery.get( url( "mock.php?action=json&header" ), data, success, "json" )
+ .then( function( json ) {
+ assert.deepEqual( json, { data: { lang: "en", length: 25 } },
+ "`dataType: \"json\"` applied with `" + data + "` data & `" +
+ success + "` success callback" );
+ done();
+ } );
+
+ jQuery.get( url( "mock.php?action=json&header" ), null, "text" )
+ .then( function( text ) {
+ assert.strictEqual( text, "{\"data\":{\"lang\":\"en\",\"length\":25}}",
+ "`dataType: \"text\"` applied with `" + data + "` data & `" +
+ success + "` success callback" );
+ done();
+ } );
+ } );
+ } );
+
//----------- jQuery.getJSON()
QUnit.test( "jQuery.getJSON( String, Hash, Function ) - JSON array", function( assert ) {