1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-06-16 04:29:21 +00:00

Fixed Object.freeze throwing error with objectOmit (#46)

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
2021-09-29 17:15:52 +02:00
committed by GitHub
parent 3524264b68
commit 9f608a52fc
2 changed files with 21 additions and 4 deletions

View File

@ -158,6 +158,18 @@ describe('Object Clone Tests', () => {
;(clone[2][0] as string) = 'zero'
expect(clone).not.toEqual(obj)
})
it('should clone with Object.freeze', () => {
const obj = Object.freeze({
pouet: 'first',
toto: 'second'
})
const clone = objectClone<Record<string, string>>(obj)
expect(clone).toEqual(obj)
clone.pouet = 'third'
expect(clone).not.toEqual(obj)
})
})
describe('Object Set Tests', () => {
@ -237,7 +249,8 @@ describe('Object Clean Tests', () => {
const obj = {a: '', b: null, c: undefined}
objectClean(obj)
expect(obj).toEqual({a: '', b: null})
})
it('should not clean when options.cleanUndefined is false', () => {
const obj2 = {a: '', b: null, c: undefined}
objectClean(obj2, {cleanUndefined: false})
expect(obj2).toEqual({a: '', b: null, c: undefined})
@ -268,6 +281,10 @@ describe('Object Omit Tests', () => {
const obj = {a: 'a', b: 'c', c: 'b'}
expect(objectOmit(obj, 'b', 'd')).toEqual({a: 'a', c: 'b'})
})
it('should work with Object.freeze', () => {
const obj = {a: 'a', b: 'c', c: 'b'}
expect(objectOmit(Object.freeze(obj), 'b', 'd')).toEqual({a: 'a', c: 'b'})
})
})
describe('Is Object Tests', () => {