diff --git a/src/core/tests/utils.test.tsx b/src/core/tests/utils.test.tsx index cac97f2613..9f1f5411b8 100644 --- a/src/core/tests/utils.test.tsx +++ b/src/core/tests/utils.test.tsx @@ -68,6 +68,30 @@ describe('core/utils', () => { const b = [1, 2] expect(partialDeepEqual(a, b)).toEqual(true) }) + + it('should return `false` if a is null and b is not', () => { + const a = null + const b = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] } + expect(partialDeepEqual(a, b)).toEqual(false) + }) + + it('should return `false` if a contains null and b is not', () => { + const a = { a: null, c: 'c', d: [] } + const b = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] } + expect(partialDeepEqual(a, b)).toEqual(false) + }) + + it('should return `false` if b is null and a is not', () => { + const a = { a: { b: 'b' }, c: 'c', d: [] } + const b = null + expect(partialDeepEqual(a, b)).toEqual(false) + }) + + it('should return `false` if b contains null and a is not', () => { + const a = { a: { b: 'b' }, c: 'c', d: [] } + const b = { a: null, c: 'c', d: [{ d: 'd ' }] } + expect(partialDeepEqual(a, b)).toEqual(false) + }) }) describe('replaceEqualDeep', () => { diff --git a/src/core/utils.ts b/src/core/utils.ts index dffaf2655d..3eb8eab3c8 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -241,7 +241,7 @@ export function partialDeepEqual(a: any, b: any): boolean { return false } - if (typeof a === 'object' && typeof b === 'object') { + if (a && b && typeof a === 'object' && typeof b === 'object') { return !Object.keys(b).some(key => !partialDeepEqual(a[key], b[key])) }