diff options
-rw-r--r-- | test/data/mock.php | 4 | ||||
-rw-r--r-- | test/unit/ajax.js | 33 |
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 ) { |