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-throw-literal": "error",
"no-trailing-spaces": "error", "no-trailing-spaces": "error",
"no-undef-init": "error", "no-undef-init": "error",
"no-underscore-dangle": "error",
"no-unsafe-finally": "error", "no-unsafe-finally": "error",
"no-unused-labels": "error", "no-unused-labels": "error",
"no-unused-vars": "off", "no-unused-vars": "off",
@ -186,4 +185,4 @@
"use-isnan": "error", "use-isnan": "error",
"valid-typeof": "off" "valid-typeof": "off"
} }
} }

View File

@ -157,6 +157,14 @@ describe('Object Equal Test', () => {
it('should not be equal if lengths are equal but content different', () => { it('should not be equal if lengths are equal but content different', () => {
expect(objectEqual({pouet: true, added: true }, {pouet: true, removed: true})).toBe(false) 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', () => { it('should not be deeply equal', () => {
expect(objectEqual({pouet: {is: true}}, {pouet: {is: false}})).toBe(false) 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 return false
} }
const item2 = y[key] const item2 = y[key]
if (item === null && item2 === null) {
return true
}
if (typeof item === 'object' && typeof item2 === 'object') { if (typeof item === 'object' && typeof item2 === 'object') {
return objectEqual(item, item2) return objectEqual(item, item2)
} }

View File

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