Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors() when err object has an enumerable message prop #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ module.exports = format((einfo, { stack }) => {

// Assign all enumerable properties and the
// message property from the error provided.
Object.assign(einfo, einfo.message);
const err = einfo.message;
Object.assign(einfo, err);
einfo.message = err.message;
einfo[MESSAGE] = err.message;

Expand Down
17 changes: 17 additions & 0 deletions test/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ errInfoProps.level = 'error';
errInfoProps.whatever = true;
errInfoProps.wut = 'some string';

const errEnumerableMsg = new Error();
errEnumerableMsg.message = 'message set later';
errEnumerableMsg.extraProp = 'an extra prop';

describe('errors()({ object })', () => {
it('errors() returns the original info', assumeFormatted(
errors(),
Expand Down Expand Up @@ -69,6 +73,19 @@ describe('errors()({ object })', () => {
assume(info.wut).equals('some string');
}
));

it('errors() still works when err.message is enumerable', assumeFormatted(
errors(),
{ level: 'info', message: errEnumerableMsg },
(info) => {
assume(info.level).is.a('string');
assume(info.message).is.a('string');
assume(info.level).equals('info');
assume(info.message).equals(errEnumerableMsg.message);
assume(info[MESSAGE]).equals(errEnumerableMsg.message);
assume(info.extraProp).equals('an extra prop');
}
));
});

describe('errors()(Error)', () => {
Expand Down