From bad541d748dcfe4220ce39409bc574f416e41b52 Mon Sep 17 00:00:00 2001 From: david0xd Date: Thu, 9 Mar 2023 11:46:05 +0100 Subject: [PATCH] Refactor test for events lockdown function --- .../lockdown/lockdown-events.test.browser.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/snaps-execution-environments/src/common/lockdown/lockdown-events.test.browser.ts b/packages/snaps-execution-environments/src/common/lockdown/lockdown-events.test.browser.ts index 337ff978d1..b94bcbfe5c 100644 --- a/packages/snaps-execution-environments/src/common/lockdown/lockdown-events.test.browser.ts +++ b/packages/snaps-execution-environments/src/common/lockdown/lockdown-events.test.browser.ts @@ -7,19 +7,19 @@ describe('lockdown events security', () => { it('should lockdown events and made event properties inaccessible', async () => { executeLockdownEvents(); - let resolvePromise: (value: unknown) => void; + const eventTarget = new EventTarget(); + const promise = new Promise((resolve) => { - resolvePromise = resolve; + eventTarget.addEventListener('just-test-event', (eventObject) => { + // eslint-disable-next-line @typescript-eslint/unbound-method + resolve(eventObject.composedPath); + }); }); - const eventTarget = new EventTarget(); - eventTarget.addEventListener('just-test-event', (eventObject) => { - // eslint-disable-next-line @typescript-eslint/unbound-method - expect(eventObject.composedPath).toBeUndefined(); - resolvePromise(true); - }); const testEvent = new Event('just-test-event'); eventTarget.dispatchEvent(testEvent); - await promise; + + const result = await promise; + expect(result).toBeUndefined(); }); });