Commit 32051e97 authored by Dave Methvin's avatar Dave Methvin

Combine parseJSON tests and fix style.

We only care about the result of parseJSON so there's no reason to feature detect the entire test.
parent 3144163f
...@@ -1148,34 +1148,27 @@ test("jQuery.parseHTML", function() { ...@@ -1148,34 +1148,27 @@ test("jQuery.parseHTML", function() {
}); });
test("jQuery.parseJSON", function(){ test("jQuery.parseJSON", function(){
expect(8); expect( 9 );
equal( jQuery.parseJSON( null ), null, "Actual null returns null" );
equal( jQuery.isEmptyObject( jQuery.parseJSON("{}") ), true, "Empty object returns empty object" );
deepEqual( jQuery.parseJSON("{\"test\":1}"), { "test": 1 }, "Plain object parses" );
deepEqual( jQuery.parseJSON("\n{\"test\":1}"), { "test": 1 }, "Leading whitespaces are ignored." );
raises(function() { raises(function() {
jQuery.parseJSON(); jQuery.parseJSON();
}, null, "parseJson now matches JSON.parse for empty input." ); }, null, "Undefined raises an error" );
equal(jQuery.parseJSON( null ), null, "parseJson now matches JSON.parse on null input." );
raises( function() { raises( function() {
jQuery.parseJSON( "" ); jQuery.parseJSON( "" );
}, null, "parseJson now matches JSON.parse for empty strings." ); }, null, "Empty string raises an error" );
raises(function() {
deepEqual( jQuery.parseJSON("{}"), {}, "Plain object parsing." ); jQuery.parseJSON("''");
deepEqual( jQuery.parseJSON("{\"test\":1}"), {"test":1}, "Plain object parsing." ); }, null, "Single-quoted string raises an error" );
raises(function() {
deepEqual( jQuery.parseJSON("\n{\"test\":1}"), {"test":1}, "Make sure leading whitespaces are handled." );
try {
jQuery.parseJSON("{a:1}"); jQuery.parseJSON("{a:1}");
ok( false, "Test malformed JSON string." ); }, null, "Unquoted property raises an error" );
} catch( e ) { raises(function() {
ok( true, "Test malformed JSON string." );
}
try {
jQuery.parseJSON("{'a':1}"); jQuery.parseJSON("{'a':1}");
ok( false, "Test malformed JSON string." ); }, null, "Single-quoted property raises an error" );
} catch( e ) {
ok( true, "Test malformed JSON string." );
}
}); });
test("jQuery.parseXML", 8, function(){ test("jQuery.parseXML", 8, function(){
...@@ -1350,53 +1343,3 @@ test("jQuery.camelCase()", function() { ...@@ -1350,53 +1343,3 @@ test("jQuery.camelCase()", function() {
equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val ); equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
}); });
}); });
// Ensure our window.JSON matches behavior of the native one, if it exists
if ( window.JSON ) {
test( "JQuery.parseJSON() equivalence to JSON.parse", function() {
expect( 10 );
var jsonParse = window.JSON;
window.JSON = null;
raises(function() {
jsonParse.parse("''");
});
raises(function() {
jQuery.parseJSON("''");
});
raises(function() {
jsonParse.parse("");
});
raises(function() {
jQuery.parseJSON("");
});
raises(function() {
jsonParse.parse({});
});
raises(function() {
jQuery.parseJSON({});
});
var parsedValue = jsonParse.parse(null);
equal( parsedValue, null, "parsed null" );
parsedValue = jQuery.parseJSON(null);
equal( parsedValue, null, "parsed null" );
parsedValue = jsonParse.parse("{}");
equal( (typeof parsedValue === "object"), true );
parsedValue = jQuery.parseJSON("{}");
equal( (typeof parsedValue === "object"), true );
window.JSON = jsonParse;
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment