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 25, 2024
1 parent 6a74046 commit dabbaaa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/object/tests/assign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ describe('assign function', () => {
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)
})
})
8 changes: 8 additions & 0 deletions src/object/tests/keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ describe('keys function', () => {
'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'])
})
})

0 comments on commit dabbaaa

Please sign in to comment.