diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index 75eefb12f7c1..cd8b2f429ed7 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -725,23 +725,30 @@ async function switchToNotificationWindow(driver) { * * @param {WebDriver} driver * @param {import('mockttp').MockedEndpoint[]} mockedEndpoints - * @param {boolean} hasRequest + * @param {boolean} [waitWhilePending] - Wait until no requests are pending * @returns {Promise} */ -async function getEventPayloads(driver, mockedEndpoints, hasRequest = true) { - await driver.wait( - async () => { - let isPending = true; - - for (const mockedEndpoint of mockedEndpoints) { - isPending = await mockedEndpoint.isPending(); - } +async function getEventPayloads( + driver, + mockedEndpoints, + waitWhilePending = true, +) { + if (waitWhilePending) { + await driver.wait( + async () => { + const pendingStatuses = await Promise.all( + mockedEndpoints.map((mockedEndpoint) => mockedEndpoint.isPending()), + ); + const isSomethingPending = pendingStatuses.some( + (pendingStatus) => pendingStatus, + ); - return isPending === !hasRequest; - }, - driver.timeout, - true, - ); + return !isSomethingPending; + }, + driver.timeout, + true, + ); + } const mockedRequests = []; for (const mockedEndpoint of mockedEndpoints) { mockedRequests.push(...(await mockedEndpoint.getSeenRequests()));