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 32113fd
Show file tree
Hide file tree
Showing 2 changed files with 9 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
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,11 @@ describe('deepEqual()', () => {
compare();
});

it('compares errors', async () => {

expect(Hoek.deepEqual(new Error(), new Error())).to.be.true();
});

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 32113fd

Please sign in to comment.