mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +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)
|
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) {
|
||||||
|
@ -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')
|
||||||
|
Loading…
Reference in New Issue
Block a user