From 2e2c9ddf7bd2ff61365990904b0d28e624f60f88 Mon Sep 17 00:00:00 2001 From: User Date: Mon, 29 Jul 2024 17:47:08 -0500 Subject: [PATCH] Refactor mailcatcher util --- frontend/tests/utils/mailcatcher.ts | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/frontend/tests/utils/mailcatcher.ts b/frontend/tests/utils/mailcatcher.ts index 2c1af62ee4..601ce434fb 100644 --- a/frontend/tests/utils/mailcatcher.ts +++ b/frontend/tests/utils/mailcatcher.ts @@ -43,22 +43,17 @@ export function findLastEmail({ ), ) - const findEmailPromise = new Promise(async (resolve, reject) => { - try { - while (true) { - const emailData = await findEmail({ request, filter }) + const checkEmails = async () => { + while (true) { + const emailData = await findEmail({ request, filter }) - if (emailData) { - resolve(emailData) - return - } - - await new Promise((resolve) => setTimeout(resolve, 100)) + if (emailData) { + return emailData } - } catch (e) { - reject(e) + // Wait for 100ms before checking again + await new Promise((resolve) => setTimeout(resolve, 100)) } - }) + } - return Promise.race([timeoutPromise, findEmailPromise]) + return Promise.race([timeoutPromise, checkEmails()]) }