condition-based-waiting

Replace arbitrary setTimeout calls with condition polling in tests.

10|Updated Dec 15, 2014
One-click install
npx skills add https://github.com/baleen37/dotfiles --skill condition-based-waiting-baleen37
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/baleen37/dotfiles/tree/main/modules/shared/config/claude/skills/condition-based-waiting
Command: npx skills add https://github.com/baleen37/dotfiles --skill condition-based-waiting-baleen37

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Flaky tests often rely on arbitrary setTimeout or sleep calls, leading to race conditions and inconsistent pass/fail rates. This skill replaces guesswork with precise condition polling, ensuring tests wait for actual state changes, making them reliable and faster.

Core Features & Use Cases

  • Reliable Async Testing: Waits for specific events, state changes, or data counts instead of fixed delays.
  • Generic Polling Function: Provides a reusable waitFor utility to implement custom conditions.
  • Domain-Specific Helpers: Includes examples like waitForEvent, waitForEventCount, and waitForEventMatch for common async scenarios.
  • Use Case: Instead of await new Promise(r => setTimeout(r, 300)); to hope tools start, use await waitForEventCount(threadManager, threadId, 'TOOL_CALL', 2); to reliably wait for two tool calls.

Quick Start

BEFORE (flaky):

await new Promise(r => setTimeout(r, 50));

const result = getResult();

expect(result).toBeDefined();

AFTER (reliable):

await waitFor(() => getResult() !== undefined, "result to be defined");

const result = getResult();

expect(result).toBeDefined();