Skip to content

armgit / mocha

Public Imported from GitHub
0

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

fix(utils/stringify): fix issue #1660

Ariel Mashrakiac13adf0149f
diff --git a/lib/utils.js b/lib/utils.js
index 3650a707..7e44edf2 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -444,7 +444,10 @@ function jsonStringify(object, spaces, depth) {
: val.toString();
break;
case 'date':
- val = '[Date: ' + val.toISOString() + ']';
+ var sDate = isNaN(val.getTime()) // Invalid date
+ ? val.toString()
+ : val.toISOString();
+ val = '[Date: ' + sDate + ']';
break;
case 'buffer':
var json = val.toJSON();
diff --git a/test/acceptance/utils.js b/test/acceptance/utils.js
index 6b373a45..e67250b6 100644
--- a/test/acceptance/utils.js
+++ b/test/acceptance/utils.js
@@ -89,6 +89,10 @@ describe('lib/utils', function () {
stringify(date).should.equal('[Date: ' + date.toISOString() + ']');
});
+ it('should return invalid Date object with .toString() + string prefix', function() {
+ stringify(new Date('')).should.equal('[Date: ' + new Date('').toString() + ']');
+ });
+
describe('#Number', function() {
it('should show the handle -0 situations', function() {
stringify(-0).should.eql('-0');