Skip to content

Commit b1b52f4

Browse files
committed
Add guard for when lhs is not an object to default value to rhs
1 parent 7c341d1 commit b1b52f4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const isEmpty = o => Object.keys(o).length === 0;
44
const diff = (lhs, rhs) => {
55
if (lhs === rhs) return {};
66

7-
if (!isObject(rhs) || rhs === null || lhs === null) return rhs;
7+
if (!isObject(lhs) || !isObject(rhs) || rhs === null || lhs === null) return rhs;
88

99
const rhsKeys = Object.keys(rhs);
1010

src/index.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ describe('.diff', () => {
2929
['hello', undefined],
3030
[null, undefined],
3131
[undefined, null],
32-
[null, { a: 1 }]
32+
[null, { a: 1 }],
33+
['872983', { areaCode: '+44', number: '872983' }]
3334
]).it('returns right hand side value when different to left hand side value (%s, %s)', (lhs, rhs) => {
3435
expect(diff(lhs, rhs)).to.deep.equal(rhs);
3536
});

0 commit comments

Comments
 (0)