diff --git a/lib/utils.js b/lib/utils.js index 7a65f92ec3..de8acaffcc 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -472,6 +472,7 @@ function jsonStringify(object, spaces, depth) { break; case 'boolean': case 'regexp': + case 'symbol': case 'number': val = val === 0 && (1 / val) === -Infinity // `-0` ? '-0' @@ -597,6 +598,7 @@ exports.canonicalize = function(value, stack) { case 'number': case 'regexp': case 'boolean': + case 'symbol': canonicalizedObj = value; break; default: diff --git a/test/acceptance/utils.js b/test/acceptance/utils.js index 053e7ca1f1..5f67f27430 100644 --- a/test/acceptance/utils.js +++ b/test/acceptance/utils.js @@ -331,6 +331,15 @@ describe('lib/utils', function () { stringify(a).should.equal('{\n "foo": 1\n}'); }); + + // In old version node.js, Symbol is not available by default. + if (typeof global.Symbol === 'function') { + it('should handle Symbol', function () { + var symbol = Symbol('value'); + stringify(symbol).should.equal('Symbol(value)'); + stringify({symbol: symbol}).should.equal('{\n "symbol": Symbol(value)\n}') + }); + } }); describe('type', function () {