test: for waitUntil

This commit is contained in:
Clark Du 2018-05-15 13:10:07 +01:00
parent e962ee19e7
commit 7bbd6c67a5
No known key found for this signature in database
GPG Key ID: 32CBD8CD478AF898
2 changed files with 7 additions and 1 deletions

View File

@ -26,7 +26,8 @@ export const waitUntil = async function waitUntil(condition, duration = 20, inte
const steps = Math.floor(duration * 1000 / interval) const steps = Math.floor(duration * 1000 / interval)
while (!condition() && iterator < steps) { while (!condition() && iterator < steps) {
await waitFor(interval) && iterator++ await waitFor(interval)
iterator++
} }
if (iterator === steps) { if (iterator === steps) {

View File

@ -23,6 +23,11 @@ describe('utils', () => {
await Utils.waitFor() await Utils.waitFor()
}) })
test('waitUntil', async () => {
expect(await Utils.waitUntil(() => true, 0.1, 100)).toBe(false)
expect(await Utils.waitUntil(() => false, 0.1, 100)).toBe(true)
})
test('timeout (promise)', async () => { test('timeout (promise)', async () => {
const result = await Utils.timeout(Promise.resolve('time not run out'), 100) const result = await Utils.timeout(Promise.resolve('time not run out'), 100)
expect(result).toBe('time not run out') expect(result).toBe('time not run out')