From e0a43d2f5a39a55e5fe62b4c8734767b8c7fc86e Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Tue, 9 Feb 2016 12:01:20 +0000 Subject: [PATCH] Handle non string error messages --- lib/reporters/base.js | 4 ++-- test/reporters/base.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index bb107ba229..5fe0eb71a6 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.js index affc7ba21c..bbd0d3a9a7 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',