diff --git a/lib/assert.js b/lib/assert.js index 55ef74493..51b1b294b 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -86,10 +86,30 @@ assert.AssertionError.prototype.toString = function() { if (this.message) { return [this.name+":", this.message].join(' '); } else { + var expectedString; + try { + expectedString = (typeof this.expected !== 'undefined' + ? JSON.stringify(this.expected) + : 'undefined'); + } + catch (e) { + return this.name + ": JSON.stringify(expected) threw exception: \"" + e + "\""; + } + + var actualString; + try { + actualString = (typeof this.actual !== 'undefined' + ? JSON.stringify(this.actual) + : 'undefined'); + } + catch (e) { + return this.name + ": JSON.stringify(actual) threw exception: \"" + e + "\""; + } + return [ this.name+":" - , typeof this.expected !== 'undefined' ? JSON.stringify(this.expected) : 'undefined' + , expectedString , this.operator - , typeof this.actual !== 'undefined' ? JSON.stringify(this.actual) : 'undefined' + , actualString ].join(" "); } };