Commit 3144163f authored by Dave Methvin's avatar Dave Methvin

Followup for #12751, only test on browsers with JSON.parse

parent c6cf30a5
...@@ -1351,49 +1351,52 @@ test("jQuery.camelCase()", function() { ...@@ -1351,49 +1351,52 @@ test("jQuery.camelCase()", function() {
}); });
}); });
test( "JQuery.parseJSON() test internal parseJson (using fallback) to make sure that it throws like JSON.parse", function() { // Ensure our window.JSON matches behavior of the native one, if it exists
expect( 10 ); if ( window.JSON ) {
test( "JQuery.parseJSON() equivalence to JSON.parse", function() {
expect( 10 );
var jsonParse = window.JSON; var jsonParse = window.JSON;
window.JSON = null; window.JSON = null;
raises(function() { raises(function() {
jsonParse.parse("''"); jsonParse.parse("''");
}); });
raises(function() { raises(function() {
jQuery.parseJSON("''"); jQuery.parseJSON("''");
}); });
raises(function() { raises(function() {
jsonParse.parse(""); jsonParse.parse("");
}); });
raises(function() { raises(function() {
jQuery.parseJSON(""); jQuery.parseJSON("");
}); });
raises(function() { raises(function() {
jsonParse.parse({}); jsonParse.parse({});
}); });
raises(function() { raises(function() {
jQuery.parseJSON({}); jQuery.parseJSON({});
}); });
var parsedValue = jsonParse.parse(null); var parsedValue = jsonParse.parse(null);
equal( parsedValue, null ); equal( parsedValue, null, "parsed null" );
parsedValue = jQuery.parseJSON(null); parsedValue = jQuery.parseJSON(null);
equal( parsedValue, null ); equal( parsedValue, null, "parsed null" );
parsedValue = jsonParse.parse("{}"); parsedValue = jsonParse.parse("{}");
equal( (typeof parsedValue === "object"), true ); equal( (typeof parsedValue === "object"), true );
parsedValue = jQuery.parseJSON("{}"); parsedValue = jQuery.parseJSON("{}");
equal( (typeof parsedValue === "object"), true ); equal( (typeof parsedValue === "object"), true );
window.JSON = jsonParse; 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