condition-based-waiting

Replace fixed timeouts with configurable condition polling in test suites.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates flaky tests caused by race conditions, timing dependencies, or inconsistent pass/fail behavior by replacing arbitrary timeouts with condition polling. It makes your test suites reliable, faster, and easier to maintain, saving significant debugging time.

Core Features & Use Cases

  • Reliable Waiting: Waits for actual state changes or events to occur, rather than guessing with fixed setTimeout or sleep delays.
  • Generic Polling Function: Provides a reusable waitFor utility that can be adapted for various conditions (e.g., waiting for an event, a state change, a file to exist, or a specific count).
  • Flaky Test Prevention: Directly addresses the root causes of unreliable test suites, improving CI/CD stability and developer confidence.
  • Use Case: Your integration tests are failing intermittently due to timing issues when an asynchronous operation completes. Use this skill to refactor them, replacing fixed delays with waitFor calls that poll for the actual completion event or state change, making your tests robust.

Quick Start

Use the condition-based-waiting skill to refactor the 'user-login.test.ts' file, replacing setTimeout calls with waitFor conditions.

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 race conditions and timing issues?

Replace arbitrary timeouts with condition-based waiting. Use a polling mechanism that checks for actual state changes or events rather than fixed delays, eliminating race conditions and making tests reliably pass regardless of system speed.

What's the best way to wait for asynchronous operations in tests?

Implement condition-based waiting with a reusable waitFor utility that polls for completion events or state changes instead of guessing with setTimeout or sleep delays, ensuring tests wait for real conditions before proceeding.

Why do my test suites fail intermittently with setTimeout delays?

Fixed timeouts cause flaky tests when asynchronous operations complete unpredictably. Condition-based waiting solves this by polling for the actual event or state change, making test behavior deterministic across different system loads.

Can I use condition-based waiting to handle parallel test execution?

Yes. Condition-based waiting with configurable timeouts and clear error handling works across parallel execution environments, preventing race condition failures by waiting for real state changes rather than guessing durations.

How do I refactor tests to replace setTimeout with condition polling?

Identify setTimeout or sleep calls blocking on asynchronous completion, then replace them with a waitFor function that accepts a condition predicate and timeout. The predicate checks for the actual state or event you're waiting for.

What types of conditions can condition-based waiting handle?

Condition-based waiting can poll for any testable state: event completion, file existence, specific counts, property changes, or DOM updates. The generic polling mechanism adapts to your condition predicate and timeout configuration.