[FIX] app: make sure we maintain the correct prototype chain in env

This commit is contained in:
Géry Debongnie
2022-03-03 15:48:29 +01:00
parent 0457e5d4ed
commit 8d1d0a2244
2 changed files with 5 additions and 2 deletions
+3 -2
View File
@@ -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);
}
+2
View File
@@ -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));
});
});