condition-based-waiting

Replace arbitrary delays with condition polling in flaky tests.

Updated Nov 14, 2025
One-click install
npx skills add https://github.com/Donaldshen27/xtrend-vanilla --skill condition-based-waiting-donaldshen27
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/Donaldshen27/xtrend-vanilla/tree/main/.claude/skills/condition-based-waiting
Command: npx skills add https://github.com/Donaldshen27/xtrend-vanilla --skill condition-based-waiting-donaldshen27

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Flaky tests often guess at timing with arbitrary delays, creating race conditions where tests pass on fast machines but fail under load or in CI. Wait for the actual condition you care about, not a guess about how long it takes.

Core Features & Use Cases

  • Condition-based waiting: Wait for a real state before continuing.
  • Utilities: waitFor, waitForEvent, waitForEventCount, and waitForEventMatch to cover common async patterns.
  • Use Case: Stabilize tests by replacing sleeps with explicit condition polling and scoped assertions.

Quick Start

Add the waitFor utilities to your test suite and replace sleep-based waits with waitFor(() => condition) or waitForEvent(...).

Frequently Asked Questions about condition-based-waiting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix flaky tests caused by arbitrary delays and race conditions?

Fix flaky tests by replacing arbitrary delays with condition polling using utilities like waitFor and waitForEvent. This waits for real states instead of guessing timing, stabilizing tests across asynchronous workflows and event-driven triggers.

What is condition-based waiting in async testing?

Condition-based waiting is a polling technique that pauses test execution until a specific state is achieved rather than relying on fixed timers. It uses utilities like waitFor and waitForEventMatch to verify real conditions with configurable timeouts.

How do I wait for a specific event count in an event-driven test workflow?

Wait for a specific event count using the waitForEventCount utility. It polls the event-driven trigger continuously until the exact number of events is matched within a configurable timeout, providing robust error messaging if conditions fail.

Does condition-based waiting work for state machines with uncertain timing?

Yes, condition-based waiting works for state machines by replacing sleeps with explicit condition polling. Utilities like waitFor and waitForEventMatch handle uncertain timing by checking the actual state before continuing test execution.

What is the best way to stabilize tests that pass locally but fail in CI?

The best way to stabilize tests is replacing sleep-based waits with explicit condition polling. Applying waitFor utilities ensures tests wait for real states and scoped assertions, eliminating timing dependencies that cause failures under CI load.

What are the limitations of using polling to wait for conditions?

Polling limitations include potential timeout failures if asynchronous workflows never reach the desired state. The utilities mitigate this with configurable timeouts and robust error messaging, but cannot verify conditions that do not eventually resolve.