☕️ Classic, reliable, trusted test framework for Node.js and the browser
Handle non string error messages
Jonathan Kime0a43d2f5a39
diff --git a/lib/reporters/base.js b/lib/reporters/base.jsindex bb107ba2..5fe0eb71 100644--- a/lib/reporters/base.js+++ b/lib/reporters/base.js@@ -170,8 +170,8 @@ exports.list = function(failures) {var msg;var err = test.err;var message;- if (err.message) {- message = err.message;+ if (err.message && typeof err.message.toString === 'function') {+ message = err.message + '';} else if (typeof err.inspect === 'function') {message = err.inspect() + '';} else {diff --git a/test/reporters/base.js b/test/reporters/base.jsindex affc7ba2..bbd0d3a9 100644--- a/test/reporters/base.js+++ b/test/reporters/base.js@@ -1,3 +1,5 @@+var assert = require('assert');+var Base = require('../../lib/reporters/base'), Assert = require('assert').AssertionError;@@ -149,6 +151,27 @@ describe('Base reporter', function () {errOut.should.match(/\+ expected/);});+ it('should handle error messages that are not strings', function () {+ var errOut;++ try {+ assert(false, true);+ } catch (err) {+ err.actual = false;+ err.expected = true;+ err.showDiff = true;+ var test = makeTest(err);++ Base.list([test]);++ errOut = stdout.join('\n');+ errOut.should.match(/\+true/);+ errOut.should.match(/\-false/);+ errOut.should.match(/\- actual/);+ errOut.should.match(/\+ expected/);+ }+ });+it('should remove message from stack', function () {var err = {message: 'Error',