condition-based-waiting

Replace sleep-based waits with configurable condition polling in tests.

Updated Feb 17, 2026
One-click install
npx skills add https://github.com/tim-hub/role-based-skills --skill condition-based-waiting-tim-hub
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/tim-hub/role-based-skills/tree/main/condition-based-waiting/condition-based-waiting
Command: npx skills add https://github.com/tim-hub/role-based-skills --skill condition-based-waiting-tim-hub

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Tests that rely on arbitrary delays often produce race conditions and intermittent failures across environments. This Skill replaces guesswork timeouts with deterministic condition polling so tests wait for actual state changes and produce consistent results.

Core Features & Use Cases

  • Polling utilities for waiting on boolean conditions, counts, or predicate-matched events.
  • Event helpers to wait for specific event types, a required number of events, or events matching custom predicates.
  • Robust timeouts and errors to avoid infinite loops and provide clear failure reasons.
  • Use cases include stabilizing unit, integration, and end-to-end tests that previously used setTimeout or sleep, coordinating async tool calls, and replacing flaky timing-based assertions.

Quick Start

Refactor the test to replace setTimeout sleeps by calling waitFor with a condition getter, a descriptive message, and a reasonable timeout so the test waits for the actual state instead of a fixed delay.

Frequently Asked Questions about condition-based-waiting

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

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

Eliminate flaky tests by replacing arbitrary sleep delays with condition polling. This ensures tests wait for actual state changes rather than fixed delays, producing deterministic and consistent results across environments.

What is condition polling and how does it fix intermittent test failures?

Condition polling continuously checks a boolean state or predicate at configured intervals until a timeout is reached. It fixes intermittent failures by synchronizing test execution on actual events instead of relying on unreliable timing guesses.

How do I replace setTimeout in end-to-end tests that rely on asynchronous events?

Replace setTimeout in end-to-end tests by implementing a waitFor helper with a condition getter and descriptive message. Configure reasonable timeouts to wait for actual state changes instead of fixed delays.

Does condition-based waiting work for unit, integration, and end-to-end tests?

Yes, condition-based waiting applies to unit, integration, and end-to-end tests. It stabilizes tests relying on timing, asynchronous events, external tool ticks, or parallel execution where fixed delays cause race conditions.

What is the best way to wait for a specific number of events in an integration test?

The best way to wait for a specific number of events is using event helpers with custom predicate matchers. This ensures the test waits for the required event count and provides explicit timeout errors for clear failure reasons.

Why do my tests fail intermittently across different environments when using fixed delays?

Tests fail intermittently because fixed delays cause race conditions when execution speeds vary across environments. Replacing guesswork timeouts with deterministic condition polling ensures tests wait for actual state changes and produce consistent results.