Skip to content

Commit

Permalink
updated error comparison method in deepEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondama committed Oct 5, 2017
1 parent 5e61577 commit 0778f53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0778f53

Please sign in to comment.