diff --git a/src/immutables.js b/src/immutables.js index 524ee38e..31bcbadb 100644 --- a/src/immutables.js +++ b/src/immutables.js @@ -179,7 +179,10 @@ export function setPath(target, path, value, index = 0) { export function same( a, b, - properties = a !== b && uniq(concat(keys(a), keys(b))), + properties = a !== b && + a != null && + b != null && + uniq(concat(keys(a), keys(b))), deep = false, ) { /* @@ -190,6 +193,9 @@ export function same( if (a === b) { return true } + if (a == null || b == null) { + return false + } const { length } = properties for (let i = 0; i < length; i++) { const property = properties[i] diff --git a/src/tests/immutables.js b/src/tests/immutables.js index 4fd7b1cb..af4d7539 100644 --- a/src/tests/immutables.js +++ b/src/tests/immutables.js @@ -249,6 +249,9 @@ test('same', (assert) => { same({ a }, { a: { b: 1 } }, ['a.b'], true), 'deeply dissimilar object', ) + assert.false(same(a, null), 'left different to null') + assert.false(same(null, b), 'right different to null') + assert.true(same(null, null), 'similar if both are null') }) test('different', (assert) => {