Skip to content

Commit

Permalink
fix(ObjectUtils): only check for hashCode on truthy objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Markon committed Nov 25, 2019
1 parent 9230196 commit 5edb119
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/utils/ObjectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export function shallowEqual(obj1: any, obj2: any): Boolean {
// While this technically means this is deep equality for Immutables,
// it's better to have a more specific check than an entirely incorrect one.
if (
obj1 &&
obj2 &&
typeof obj1.hashCode === 'function' &&
typeof obj2.hashCode === 'function'
) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/__tests__/ObjectUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,9 @@ describe('ObjectUtils', () => {
// force hash collision - should fall back to .equals
expect(shallowEqual(mockImmutable1, mockImmutable2)).toBe(false);
});

it('handles immutable values if one input is falsy', () => {
expect(() => shallowEqual(Map({ a: 1 }), null)).not.toThrow();
});
});
});

0 comments on commit 5edb119

Please sign in to comment.