Skip to content

Commit

Permalink
fix: updating timeout logic. Resolves issue #464
Browse files Browse the repository at this point in the history
  • Loading branch information
liambutler committed May 22, 2023
1 parent 3d6d74d commit 54a4ff8
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand All @@ -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()
})
}
Expand Down

0 comments on commit 54a4ff8

Please sign in to comment.