Skip to content

Commit d6f8e77

Browse files
author
tomzu
committed
added test for waitUntil
1 parent ecd939e commit d6f8e77

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/core/src/test/shared/utilities/timeoutUtils.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,46 @@ export const timeoutUtilsDescribe = describe('timeoutUtils', async function () {
394394
fn = sandbox.stub()
395395
})
396396

397+
it('should retry when retryOnFail callback returns true', async function () {
398+
fn.onCall(0).throws(new Error('Retry error'))
399+
fn.onCall(1).throws(new Error('Retry error'))
400+
fn.onCall(2).resolves('success')
401+
402+
const res = waitUntil(fn, {
403+
retryOnFail: (error: Error) => {
404+
return error.message === 'Retry error'
405+
},
406+
})
407+
408+
await clock.tickAsync(timeoutUtils.waitUntilDefaultInterval)
409+
assert.strictEqual(fn.callCount, 2)
410+
await clock.tickAsync(timeoutUtils.waitUntilDefaultInterval)
411+
assert.strictEqual(fn.callCount, 3)
412+
assert.strictEqual(await res, 'success')
413+
})
414+
415+
it('should not retry when retryOnFail callback returns false', async function () {
416+
fn.onCall(0).throws(new Error('Retry error'))
417+
fn.onCall(1).throws(new Error('Retry error'))
418+
fn.onCall(2).throws(new Error('Last error'))
419+
fn.onCall(3).resolves('this is not hit')
420+
421+
const res = assert.rejects(
422+
waitUntil(fn, {
423+
retryOnFail: (error: Error) => {
424+
return error.message === 'Retry error'
425+
},
426+
}),
427+
(e) => e instanceof Error && e.message === 'Last error'
428+
)
429+
430+
await clock.tickAsync(timeoutUtils.waitUntilDefaultInterval)
431+
assert.strictEqual(fn.callCount, 2)
432+
await clock.tickAsync(timeoutUtils.waitUntilDefaultInterval)
433+
assert.strictEqual(fn.callCount, 3)
434+
await res
435+
})
436+
397437
it('retries the function until it succeeds', async function () {
398438
fn.onCall(0).throws()
399439
fn.onCall(1).throws()

0 commit comments

Comments
 (0)