Skip to content

Commit 305da23

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-4989 Ref jquery/api.jquery.com#1208
1 parent 447432f commit 305da23

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
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

+32-1
Original file line numberDiff line numberDiff line change
@@ -2782,7 +2782,7 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
27822782
} );
27832783
} );
27842784

2785-
QUnit.test( "jQuery.get( String, null-ish, String ) - dataType with null callback (gh-4989)",
2785+
QUnit.test( "jQuery.get( String, null, String ) - dataType with null callback (gh-4989)",
27862786
function( assert ) {
27872787
assert.expect( 2 );
27882788
var done = assert.async( 2 );
@@ -2802,6 +2802,37 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
28022802
} );
28032803
} );
28042804

2805+
QUnit.test( "jQuery.get( String, null-ish, null-ish, String ) - dataType with null/undefined data & callback",
2806+
function( assert ) {
2807+
assert.expect( 8 );
2808+
var done = assert.async( 8 );
2809+
2810+
[
2811+
{ data: null, success: null },
2812+
{ data: null, success: undefined },
2813+
{ data: undefined, success: null },
2814+
{ data: undefined, success: undefined }
2815+
].forEach( function( options ) {
2816+
var data = options.data,
2817+
success = options.success;
2818+
jQuery.get( url( "mock.php?action=json&header" ), data, success, "json" )
2819+
.then( function( json ) {
2820+
assert.deepEqual( json, { data: { lang: "en", length: 25 } },
2821+
"`dataType: \"json\"` applied with `" + data + "` data & `" +
2822+
success + "` success callback" );
2823+
done();
2824+
} );
2825+
2826+
jQuery.get( url( "mock.php?action=json&header" ), null, "text" )
2827+
.then( function( text ) {
2828+
assert.strictEqual( text, "{\"data\":{\"lang\":\"en\",\"length\":25}}",
2829+
"`dataType: \"text\"` applied with `" + data + "` data & `" +
2830+
success + "` success callback" );
2831+
done();
2832+
} );
2833+
} );
2834+
} );
2835+
28052836
//----------- jQuery.getJSON()
28062837

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

0 commit comments

Comments
 (0)