Skip to content

Commit ef9f4b4

Browse files
committed
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. Ref jquerygh-5640 Ref jquerygh-4989 Ref jquery/api.jquery.com#1208
1 parent 454d52d commit ef9f4b4

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

test/data/mock.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ protected function json( $req ) {
9595
}
9696

9797
if ( isset( $req->query['array'] ) ) {
98-
echo '[ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ]';
98+
echo '[{"name":"John","age":21},{"name":"Peter","age":25}]';
9999
} else {
100-
echo '{ "data": {"lang": "en", "length": 25} }';
100+
echo '{"data":{"lang":"en","length":25}}';
101101
}
102102
}
103103

test/unit/ajax.js

+31
Original file line numberDiff line numberDiff line change
@@ -2648,6 +2648,37 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
26482648
} );
26492649
} );
26502650

2651+
QUnit.test( "jQuery.get( String, null-ish, null-ish, String ) - dataType with null/undefined data & callback",
2652+
function( assert ) {
2653+
assert.expect( 8 );
2654+
var done = assert.async( 8 );
2655+
2656+
[
2657+
{ data: null, success: null },
2658+
{ data: null, success: undefined },
2659+
{ data: undefined, success: null },
2660+
{ data: undefined, success: undefined }
2661+
].forEach( function( options ) {
2662+
var data = options.data,
2663+
success = options.success;
2664+
jQuery.get( url( "mock.php?action=json&header" ), data, success, "json" )
2665+
.then( function( json ) {
2666+
assert.deepEqual( json, { data: { lang: "en", length: 25 } },
2667+
"`dataType: \"json\"` applied with `" + data + "` data & `" +
2668+
success + "` success callback" );
2669+
done();
2670+
} );
2671+
2672+
jQuery.get( url( "mock.php?action=json&header" ), data, success, "text" )
2673+
.then( function( text ) {
2674+
assert.strictEqual( text, "{\"data\":{\"lang\":\"en\",\"length\":25}}",
2675+
"`dataType: \"text\"` applied with `" + data + "` data & `" +
2676+
success + "` success callback" );
2677+
done();
2678+
} );
2679+
} );
2680+
} );
2681+
26512682
//----------- jQuery.getJSON()
26522683

26532684
QUnit.test( "jQuery.getJSON( String, Hash, Function ) - JSON array", function( assert ) {

0 commit comments

Comments
 (0)