Read this in other languages: English | 简体中文
Experience the untiljs features online Edit in CodeSandbox
# use pnpm
$ pnpm install untiljs
# use npm
$ npm install untiljs --save
# use yarn
$ yarn add untiljs
import { ref } from 'vue'
import until from 'untiljs'
const val = ref(1)
setTimeout(() => {
val.value = 2
}, 1000)
;(async () => {
await until(val).toBe(2)
// state is now ready
})()
import { ref } from 'vue'
import until from 'untiljs'
const val = ref(1)
setTimeout(() => {
val.value = 2
}, 1000)
;(async () => {
await until(val).toMatch(value => value > 1)
// state is now ready
})()
import { ref } from 'vue'
import until from 'untiljs'
const val = ref(1)
setTimeout(() => {
val.value = 2
}, 1000)
;(async () => {
await until(val).not.toBe(ref(2), { timeout: 500, throwOnTimeout: true })
// reject timeout
})()
import { ref } from 'vue'
import until from 'untiljs'
const val = ref(1)
setTimeout(() => {
val.value = 2
}, 1000)
;(async () => {
await until(ref).toBe(true)
await until(ref).toMatch(v => v > 5 && v < 10)
await until(ref).changed()
await until(ref).changedTimes(2)
await until(ref).toBeTruthy()
await until(ref).toBeNull()
await until(ref).not.toBeNull()
await until(ref).not.toBeTruthy()
})()
<script src="https://unpkg.com/vue-demi@latest/lib/index.iife.js"></script>
<script src="https://unpkg.com/untiljs@latest/dist/index.min.js"></script>
<script>
await until(val).toBe(true)
// ...
</script>
Please open an issue here.