Files
element-plus/packages/test-utils/stable-load.ts
sea 63c7cd69fe test: image stable loading in CI (#22491)
* test: image stable loading in CI

* test: avatar update
2025-10-16 17:59:37 +08:00

24 lines
530 B
TypeScript

import { nextTick } from 'vue'
import { flushPromises } from '@vue/test-utils'
export async function stableLoad(
condition: () => boolean,
timeout = 3000,
interval = 100
) {
const startTime = Date.now()
while (Date.now() - startTime < timeout) {
if (condition()) return
await nextTick()
await flushPromises()
if (condition()) return
await new Promise((resolve) => setTimeout(resolve, interval))
}
if (!condition()) {
throw new Error(`Condition not met within ${timeout}ms timeout`)
}
}