Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 3144163f61ea89855818fab597a2b5f1074d10c3 1 parent c6cf30a
@dmethvin dmethvin authored
Showing with 36 additions and 33 deletions.
  1. +36 −33 test/unit/core.js
View
69 test/unit/core.js
@@ -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() {
- expect( 10 );
+// 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;
+ var jsonParse = window.JSON;
+ window.JSON = null;
- raises(function() {
- jsonParse.parse("''");
- });
+ raises(function() {
+ jsonParse.parse("''");
+ });
- raises(function() {
- jQuery.parseJSON("''");
- });
+ raises(function() {
+ jQuery.parseJSON("''");
+ });
- raises(function() {
- jsonParse.parse("");
- });
+ raises(function() {
+ jsonParse.parse("");
+ });
- raises(function() {
- jQuery.parseJSON("");
- });
+ raises(function() {
+ jQuery.parseJSON("");
+ });
- raises(function() {
- jsonParse.parse({});
- });
+ raises(function() {
+ jsonParse.parse({});
+ });
- raises(function() {
- jQuery.parseJSON({});
- });
+ raises(function() {
+ jQuery.parseJSON({});
+ });
- var parsedValue = jsonParse.parse(null);
- equal( parsedValue, null );
+ var parsedValue = jsonParse.parse(null);
+ equal( parsedValue, null, "parsed null" );
- parsedValue = jQuery.parseJSON(null);
- equal( parsedValue, null );
+ parsedValue = jQuery.parseJSON(null);
+ equal( parsedValue, null, "parsed null" );
- parsedValue = jsonParse.parse("{}");
- equal( (typeof parsedValue === "object"), true );
+ parsedValue = jsonParse.parse("{}");
+ equal( (typeof parsedValue === "object"), true );
- parsedValue = jQuery.parseJSON("{}");
- equal( (typeof parsedValue === "object"), true );
-
+ parsedValue = jQuery.parseJSON("{}");
+ equal( (typeof parsedValue === "object"), true );
+
- window.JSON = jsonParse;
-} );
+ window.JSON = jsonParse;
+ });
+}
Please sign in to comment.
Something went wrong with that request. Please try again.