mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
test: for waitUntil
This commit is contained in:
parent
e962ee19e7
commit
7bbd6c67a5
@ -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) {
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user