Skip to content

Commit

Permalink
Fix: control stringification of error message (#4128)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dayzen authored May 28, 2021
1 parent 1b5cbf1 commit 1c4e623
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ exports.list = function(failures) {
err = test.err;
}
var message;
if (err.message && typeof err.message.toString === 'function') {
message = err.message + '';
} else if (typeof err.inspect === 'function') {
if (typeof err.inspect === 'function') {
message = err.inspect() + '';
} else if (err.message && typeof err.message.toString === 'function') {
message = err.message + '';
} else {
message = '';
}
Expand Down
18 changes: 10 additions & 8 deletions test/reporters/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,22 +366,24 @@ describe('Base reporter', function() {
expect(errOut, 'to be', '1) test title:\n Error\n foo\n bar');
});

it("should use 'inspect' if 'message' is not set", function() {
var err = {
showDiff: false,
inspect: function() {
return 'an error happened';
}
it("should use 'inspect' if 'inspect' and 'message' are set", function() {
var err = new Error('test');
err.showDiff = false;
err.message = 'error message';
err.inspect = function() {
return 'Inspect Error';
};

var test = makeTest(err);

list([test]);

var errOut = stdout.join('\n').trim();
expect(errOut, 'to be', '1) test title:\n an error happened');

expect(errOut, 'to contain', 'Inspect Error');
});

it("should set an empty message if neither 'message' nor 'inspect' is set", function() {
it("should set an empty message if neither 'inspect' nor 'message' is set", function() {
var err = {
showDiff: false
};
Expand Down

0 comments on commit 1c4e623

Please sign in to comment.