From 8d1d0a2244f0e4677ad4849622ea80f595abdf69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 3 Mar 2022 15:48:29 +0100 Subject: [PATCH] [FIX] app: make sure we maintain the correct prototype chain in env --- src/app/app.ts | 5 +++-- tests/components/env.test.ts | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/app.ts b/src/app/app.ts index cb083fc7..61de942d 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -52,8 +52,9 @@ export class App< console.info(DEV_MSG()); hasBeenLogged = true; } - const descrs = Object.getOwnPropertyDescriptors(config.env || {}); - this.env = Object.freeze(Object.defineProperties({}, descrs)) as E; + const env = config.env || {}; + const descrs = Object.getOwnPropertyDescriptors(env); + this.env = Object.freeze(Object.create(Object.getPrototypeOf(env), descrs)); this.props = config.props || ({} as P); } diff --git a/tests/components/env.test.ts b/tests/components/env.test.ts index d1a1bf87..c32b0bb6 100644 --- a/tests/components/env.test.ts +++ b/tests/components/env.test.ts @@ -49,5 +49,7 @@ describe("env handling", () => { await new App(Test, { env }).mount(fixture); expect(child.env).toEqual(env); + // we check that the frozen env maintain the same prototype chain + expect(Object.getPrototypeOf(child.env)).toBe(Object.getPrototypeOf(env)); }); });