Skip to content

Commit 7c341d1

Browse files
committed
Add catch for when lhs is null and rhs is an object
1 parent 2afedd7 commit 7c341d1

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 (typeof rhs !== 'object' || rhs === null) return rhs;
7+
if (!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
@@ -28,7 +28,8 @@ describe('.diff', () => {
2828
['hello', null],
2929
['hello', undefined],
3030
[null, undefined],
31-
[undefined, null]
31+
[undefined, null],
32+
[null, { a: 1 }]
3233
]).it('returns right hand side value when different to left hand side value (%s, %s)', (lhs, rhs) => {
3334
expect(diff(lhs, rhs)).to.deep.equal(rhs);
3435
});

0 commit comments

Comments
 (0)