mirror of
https://github.com/element-plus/element-plus.git
synced 2025-12-19 09:09:40 +08:00
24 lines
530 B
TypeScript
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`)
|
|
}
|
|
}
|