Skip to content

Commit 0778f53

Browse files
committed
updated error comparison method in deepEqual
related to hapijs#213 Updated based on [nodejs/node#15001](https://github.com/nodejs/node/pull/15001/files#diff-f76cd6d4ba3dad8b6b9a393af1fce15bR202)
1 parent 5e61577 commit 0778f53

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎lib/index.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ exports.deepEqual = function (obj, ref, options, seen) {
337337
return (ref instanceof RegExp && obj.toString() === ref.toString());
338338
}
339339

340+
if (obj instanceof Error) {
341+
return (ref instanceof Error && obj.message === ref.message);
342+
}
343+
340344
if (options.prototype) {
341345
if (Object.getPrototypeOf(obj) !== Object.getPrototypeOf(ref)) {
342346
return false;

‎test/index.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,12 @@ describe('deepEqual()', () => {
10311031
compare();
10321032
});
10331033

1034+
it('compares errors', async () => {
1035+
1036+
expect(Hoek.deepEqual(new Error(), new Error())).to.be.true();
1037+
expect(Hoek.deepEqual(new Error(), { message: '' })).to.be.false();
1038+
});
1039+
10341040
it('compares dates', async () => {
10351041

10361042
expect(Hoek.deepEqual(new Date(2015, 1, 1), new Date(2015, 1, 1))).to.be.true();

0 commit comments

Comments
 (0)