Skip to content

Commit

Permalink
test: assign/keys with Object.create(null)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jun 24, 2024
1 parent 97f6ee6 commit 74613fe
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/tests/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,15 @@ describe('object module', () => {
const result = _.assign({}, { b: 'y' })
expect(result).toEqual({ b: 'y' })
})
test('works with Object.create(null)', () => {
const object = { a: Object.create(null) }
object.a.b = 1

const result = _.assign(object, { a: { c: 2 } })

expect(result).toEqual({ a: { b: 1, c: 2 } })
expect(Object.getPrototypeOf(result.a)).toBe(null)
})
})

describe('keys function', () => {
Expand Down Expand Up @@ -477,6 +486,14 @@ describe('object module', () => {
'enemies.0.power'
])
})
test('works with Object.create(null)', () => {
const object = Object.create(null)
object.a = 1
object.b = [2]
object.c = { d: 3 }
const result = _.keys(object)
expect(result).toEqual(['a', 'b.0', 'c.d'])
})
})

describe('set function', () => {
Expand Down

0 comments on commit 74613fe

Please sign in to comment.