diff --git a/src/sandbox/__tests__/proxySandbox.test.ts b/src/sandbox/__tests__/proxySandbox.test.ts index 1c3694a..fb0242b 100644 --- a/src/sandbox/__tests__/proxySandbox.test.ts +++ b/src/sandbox/__tests__/proxySandbox.test.ts @@ -332,3 +332,18 @@ test('falsy values should return as expected', () => { expect(proxy.nullvar).toBeNull(); expect(proxy.zero).toBe(0); }); + +it('should return true while [[GetPrototypeOf]] invoked by proxy object', () => { + // window.__proto__ not equals window prototype in jest environment + // eslint-disable-next-line no-proto + expect(window.__proto__ === Object.getPrototypeOf(window)).toBeFalsy(); + // we must to set the prototype of window as jest modified window `__proto__` property but not changed it internal [[Prototype]] property + // eslint-disable-next-line no-proto + Object.setPrototypeOf(window, window.__proto__); + + const { proxy } = new ProxySandbox('window-prototype'); + expect(proxy instanceof Window).toBeTruthy(); + expect(Object.getPrototypeOf(proxy)).toBe(Object.getPrototypeOf(window)); + expect(Reflect.getPrototypeOf(proxy)).toBe(Reflect.getPrototypeOf(window)); + expect(Reflect.getPrototypeOf(proxy)).toBe(Object.getPrototypeOf(window)); +}); diff --git a/src/sandbox/proxySandbox.ts b/src/sandbox/proxySandbox.ts index 79c43bc..c46fa7f 100644 --- a/src/sandbox/proxySandbox.ts +++ b/src/sandbox/proxySandbox.ts @@ -332,6 +332,11 @@ export default class ProxySandbox implements SandBox { return true; }, + + // makes sure `window instanceof Window` returns truthy in micro app + getPrototypeOf() { + return Reflect.getPrototypeOf(rawWindow); + }, }); this.proxy = proxy;