diff --git a/core/runtime/src/impl/EggObjectUtil.ts b/core/runtime/src/impl/EggObjectUtil.ts index c702448a..d9c23b36 100644 --- a/core/runtime/src/impl/EggObjectUtil.ts +++ b/core/runtime/src/impl/EggObjectUtil.ts @@ -10,7 +10,7 @@ export class EggObjectUtil { get(): any { return eggObject.obj; }, - configurable: false, + configurable: true, enumerable: true, }; } @@ -22,7 +22,7 @@ export class EggObjectUtil { const eggObject = EggContainerFactory.getEggObject(proto, objName); return eggObject.obj; }, - configurable: false, + configurable: true, enumerable: true, }; } diff --git a/core/runtime/test/EggObject.test.ts b/core/runtime/test/EggObject.test.ts index d0863dca..6ce2f003 100644 --- a/core/runtime/test/EggObject.test.ts +++ b/core/runtime/test/EggObject.test.ts @@ -4,6 +4,7 @@ import { EggTestContext } from './fixtures/EggTestContext'; import TestUtil from './util'; import { EggContainerFactory } from '..'; import { Foo, Bar } from './fixtures/modules/lifecycle-hook/object'; +import { Bar as ExtendsBar } from './fixtures/modules/extends-module/Base'; import mm from 'mm'; import { ContextHandler } from '../src/model/ContextHandler'; import { SingletonBar } from './fixtures/modules/inject-context-to-singleton/object'; @@ -101,4 +102,25 @@ describe('test/EggObject.test.ts', () => { await ctx.destroy({}); }); }); + + describe('property mock', () => { + beforeEach(() => { + mm(ContextHandler, 'getContext', () => { + return ctx; + }); + }); + + it('should work', async () => { + const instance = await TestUtil.createLoadUnitInstance('extends-module'); + const barProto = EggPrototypeFactory.instance.getPrototype('bar', instance.loadUnit); + const barObj = await EggContainerFactory.getOrCreateEggObject(barProto, barProto.name); + const bar = barObj.obj as ExtendsBar; + const foo = {}; + mm(bar, 'foo', foo); + assert(bar.foo === foo); + + await TestUtil.destroyLoadUnitInstance(instance); + await ctx.destroy({}); + }); + }); });