Skip to content

Playground

Try UntilJS interactively! Experiment with different methods and see how they work.

PlaygroundtoBe() - Wait until equals a value
Generated Code
import until from 'untiljs'

let value = 0
setTimeout(() => {
  value = 5
}, 1000)

await until(() => value).toBe(5)
console.log('Condition met!')

Tips

  • Use toMatch() for custom conditions like v > 3 or v.includes('text')
  • Use not.* to invert any condition, e.g., not.toBe(5)
  • Add { timeout: 3000, throwOnTimeout: true } to throw on timeout
  • Use { deep: true } for deep object comparison

Quick Examples

Basic Usage

typescript
import until from 'untiljs'

// Wait for a value
let count = 0
setTimeout(() => count = 5, 1000)
await until(() => count).toBe(5)

// Wait for custom condition
await until(() => count).toMatch(v => v > 3)

// Wait for truthy value
let data = null
setTimeout(() => data = { name: 'John' }, 500)
await until(() => data).toBeTruthy()

With Timeout

typescript
// Timeout without throwing
const result = await until(() => value).toBe(5, { timeout: 3000 })

// Timeout with throwing
try {
  await until(() => value).toBe(5, { timeout: 3000, throwOnTimeout: true })
} catch (e) {
  console.log('Timed out!')
}

With Deep Comparison

typescript
let config = { server: { port: 3000 } }
setTimeout(() => {
  config = { server: { port: 8080 } }
}, 500)

await until(() => config).toBe(
  { server: { port: 8080 } },
  { deep: true }
)

Not Modifier

typescript
// Wait until NOT null
let data = null
setTimeout(() => data = 'loaded', 500)
await until(() => data).not.toBeNull()

// Wait until NOT equal
let value = 5
setTimeout(() => value = 10, 500)
await until(() => value).not.toBe(5)

Released under the MIT License.