1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-04-22 10:52:11 +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:
Florian Bouillon 2020-11-23 02:27:16 +01:00
parent 4637abeaaf
commit f87e3047fc
4 changed files with 13 additions and 3 deletions

View File

@ -160,7 +160,6 @@
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-underscore-dangle": "error",
"no-unsafe-finally": "error",
"no-unused-labels": "error",
"no-unused-vars": "off",

View File

@ -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)
})

View File

@ -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)
}

View File

@ -15,7 +15,7 @@
"allowJs": true,
"sourceMap": false,
"strict": true,
"target": "ES2017", // Follow NodeJS oldest supported LTS
"target": "ES2017", // Follow NodeJS oldest supported LTS and compare with https://node.green
"module": "commonjs"
},
"exclude": [