-
-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Description
When using expect().not for matcher negation, the isNot may not be processed correctly.
- When using
wait : 0 - When the condition function result is false on the first call, but could be true later on.
onst waitUntil = async (
condition: () => Promise<boolean>,
isNot = false,
{ wait = DEFAULT_OPTIONS.wait, interval = DEFAULT_OPTIONS.interval } = {}
): Promise<boolean> => {
// single attempt
if (wait === 0) {
return await condition() // Missing isNot check here
}
let error: Error | undefined
// wait for condition to be truthy
try {
const start = Date.now()
while (true) {
if (Date.now() - start > wait) {
throw new Error('timeout')
}
try {
// should not use isNot, should finish the condition until it is true and use it outside the while loop
const result = isNot !== (await condition()) after
error = undefined
if (result) {
break
}
await sleep(interval)
} catch (err) {
error = err
await sleep(interval)
}
}
if (error) {
throw error
}
return !isNot
} catch {
if (error) {
throw error
}
return isNot
}
}
Metadata
Metadata
Assignees
Labels
No labels