From 03ab2233f7bd77c724b09dc00aa7617751e2ee89 Mon Sep 17 00:00:00 2001 From: Liam Butler Date: Mon, 22 May 2023 20:00:26 +0200 Subject: [PATCH] fix: updating timeout logic. Resolves issue #464 --- src/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 3270d24..99861df 100644 --- a/src/index.js +++ b/src/index.js @@ -47,7 +47,7 @@ const waitUntil = (subject, checkFunction, originalOptions = {}) => { // filter out a falsy passed "customMessage" value options.customMessage = [options.customMessage, originalOptions].filter(Boolean) - let retries = Math.floor(options.timeout / options.interval) + const endTime = Date.now() + options.timeout logCommand({ options, originalOptions }) @@ -56,13 +56,12 @@ const waitUntil = (subject, checkFunction, originalOptions = {}) => { if (result) { return result } - if (retries < 1) { + if (Date.now() >= endTime) { const msg = options.errorMsg instanceof Function ? options.errorMsg(result, options) : options.errorMsg throw new Error(msg) } cy.wait(options.interval, { log: false }).then(() => { - retries-- return resolveValue() }) }