mirror of
https://github.com/dzeiocom/libs.git
synced 2025-06-12 19:09:18 +00:00
Fixed bug where null were considered as objects
Signed-off-by: Florian BOUILLON <florian.bouillon@delta-wings.net>
This commit is contained in:
@ -157,6 +157,14 @@ describe('Object Equal Test', () => {
|
||||
it('should not be equal if lengths are equal but content different', () => {
|
||||
expect(objectEqual({pouet: true, added: true }, {pouet: true, removed: true})).toBe(false)
|
||||
})
|
||||
it('should be equal object contains null', () => {
|
||||
expect(objectEqual({pouet: null, added: true }, {pouet: true, added: true})).toBe(false)
|
||||
expect(objectEqual({pouet: null, added: true }, {pouet: null, added: true})).toBe(true)
|
||||
})
|
||||
it('should be equal object contains undefined', () => {
|
||||
expect(objectEqual({pouet: undefined, added: true }, {pouet: true, added: true})).toBe(false)
|
||||
expect(objectEqual({pouet: undefined, added: true }, {pouet: undefined, added: true})).toBe(true)
|
||||
})
|
||||
it('should not be deeply equal', () => {
|
||||
expect(objectEqual({pouet: {is: true}}, {pouet: {is: false}})).toBe(false)
|
||||
})
|
||||
|
@ -139,6 +139,9 @@ export function objectEqual(x: Record<string, any>, y: Record<string, any>): boo
|
||||
return false
|
||||
}
|
||||
const item2 = y[key]
|
||||
if (item === null && item2 === null) {
|
||||
return true
|
||||
}
|
||||
if (typeof item === 'object' && typeof item2 === 'object') {
|
||||
return objectEqual(item, item2)
|
||||
}
|
||||
|
Reference in New Issue
Block a user