condition-based-waiting

Replace sleep-based waits with polling loops that return awaited results.

1|1|Updated Sep 22, 2025
One-click install
npx skills add https://github.com/SkogAI/skillsandknowledge --skill condition-based-waiting-skogai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/SkogAI/skillsandknowledge/tree/main/actions/condition-based-waiting
Command: npx skills add https://github.com/SkogAI/skillsandknowledge --skill condition-based-waiting-skogai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps teams eliminate flaky tests caused by race conditions and timing dependencies by replacing arbitrary timeouts with condition polling to wait for actual state changes.

Core Features & Use Cases

  • Deterministic waits: waitFor(() => state === 'ready') ensures tests proceed only when the desired state is achieved.
  • Broad applicability: works across unit, integration, and end-to-end tests involving asynchronous operations.
  • Improved reliability: reduces intermittent failures in CI and local development by avoiding fixed delays.

Quick Start

Use the condition-based waiting technique to wait for a needed value, for example: await waitFor(() => result !== undefined).

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 arbitrary sleep-based waits in TypeScript?

Condition polling replaces fixed delays by continuously checking an asynchronous state until a condition is met or a timeout occurs. This deterministic mechanism ensures tests proceed only when the desired state is achieved, eliminating race conditions.

How do I implement deterministic waits for asynchronous state changes in end-to-end tests?

Deterministic waits are implemented using a polling loop with a timeout, such as waitFor(() => state === 'ready'). This mechanism waits for actual state changes and returns the awaited result, providing clear error messaging on timeout.

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

Yes, condition-based waiting works across unit, integration, and end-to-end tests involving asynchronous operations. It applies broadly to any testing environment where asynchronous state changes occur, enabling deterministic behavior in CI and local development.

What's the best way to wait for a needed value in TypeScript tests instead of using timeouts?

The best way to wait for a needed value is condition-based waiting: await waitFor(() => result !== undefined). This approach polls for the actual state change rather than relying on fixed delays, reducing intermittent failures.

Why does my polling loop fail intermittently in CI, and how can I improve test stability?

Polling loops fail intermittently in CI due to race conditions and timing dependencies. Improve test stability by replacing arbitrary timeouts with condition polling that includes a timeout limit and clear error messaging on failure.