From 74613feba3d66830c96c57cf6453b99569ae438d Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Mon, 24 Jun 2024 03:06:12 -0400 Subject: [PATCH] test: assign/keys with Object.create(null) --- src/tests/object.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/tests/object.test.ts b/src/tests/object.test.ts index 4f2ee7f0f..e43e65554 100644 --- a/src/tests/object.test.ts +++ b/src/tests/object.test.ts @@ -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', () => { @@ -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', () => {