From 7bbd6c67a55c66016f9af87e62db30a6c1e25c9c Mon Sep 17 00:00:00 2001 From: Clark Du Date: Tue, 15 May 2018 13:10:07 +0100 Subject: [PATCH] test: for waitUntil --- lib/common/utils.js | 3 ++- test/unit/utils.test.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/common/utils.js b/lib/common/utils.js index 2d42003a79..79d9041145 100644 --- a/lib/common/utils.js +++ b/lib/common/utils.js @@ -26,7 +26,8 @@ export const waitUntil = async function waitUntil(condition, duration = 20, inte const steps = Math.floor(duration * 1000 / interval) while (!condition() && iterator < steps) { - await waitFor(interval) && iterator++ + await waitFor(interval) + iterator++ } if (iterator === steps) { diff --git a/test/unit/utils.test.js b/test/unit/utils.test.js index 1701177102..81ec6d4f95 100644 --- a/test/unit/utils.test.js +++ b/test/unit/utils.test.js @@ -23,6 +23,11 @@ describe('utils', () => { 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 () => { const result = await Utils.timeout(Promise.resolve('time not run out'), 100) expect(result).toBe('time not run out')