Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

handle Symbol values in util.stringify()

ryym872684f44f67
diff --git a/lib/utils.js b/lib/utils.js
index 7a65f92e..de8acaff 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 053e7ca1..5f67f274 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 () {