fix(shallow): undefined value (#3205)

* add failing test

* check with .has
This commit is contained in:
Daishi Kato 2025-08-20 07:52:06 +09:00 committed by GitHub
parent c4085a4ff0
commit 2cc19881fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View File

@ -19,7 +19,7 @@ const compareEntries = (
return false
}
for (const [key, value] of mapA) {
if (!Object.is(value, mapB.get(key))) {
if (!mapB.has(key) || !Object.is(value, mapB.get(key))) {
return false
}
}

View File

@ -170,6 +170,10 @@ describe('shallow', () => {
const arr = [1, 2]
expect(shallow([arr, 1], [arr, 1])).toBe(true)
})
it('should work with undefined (#3204)', () => {
expect(shallow({ a: undefined }, { b: 1 })).toBe(false)
})
})
describe('mixed cases', () => {