diff --git a/lib/index.js b/lib/index.js index 79912f0b..60376c5d 100755 --- a/lib/index.js +++ b/lib/index.js @@ -337,6 +337,10 @@ exports.deepEqual = function (obj, ref, options, seen) { return (ref instanceof RegExp && obj.toString() === ref.toString()); } + if (obj instanceof Error) { + return (ref instanceof Error && obj.message === ref.message); + } + if (options.prototype) { if (Object.getPrototypeOf(obj) !== Object.getPrototypeOf(ref)) { return false; diff --git a/test/index.js b/test/index.js index 710b2477..7ad0c974 100755 --- a/test/index.js +++ b/test/index.js @@ -1031,6 +1031,12 @@ describe('deepEqual()', () => { compare(); }); + it('compares errors', async () => { + + expect(Hoek.deepEqual(new Error(), new Error())).to.be.true(); + expect(Hoek.deepEqual(new Error(), { message: '' })).to.be.false(); + }); + it('compares dates', async () => { expect(Hoek.deepEqual(new Date(2015, 1, 1), new Date(2015, 1, 1))).to.be.true();