condition-based-waiting

Replace arbitrary test delays with condition-based waiting patterns.

127|19|Updated Oct 23, 2025
One-click install
npx skills add https://github.com/rileyhilliard/claude-essentials --skill condition-based-waiting-rileyhilliard
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/rileyhilliard/claude-essentials/tree/main/plugins/ce/skills/condition-based-waiting
Command: npx skills add https://github.com/rileyhilliard/claude-essentials --skill condition-based-waiting-rileyhilliard

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Flaky tests often arise from timing assumptions and arbitrary delays. This skill provides a structured approach to replace sleeps and timeouts with condition-based waiting, delivering deterministic test outcomes.

Core Features & Use Cases

  • Pattern-based waiting: Use waitFor or polling utilities to wait for a real condition rather than sleeping for a fixed time.
  • Language-agnostic patterns: Concepts apply across TypeScript, Python, and other test frameworks; examples cover Jest/Testing Library, Playwright, and pytest.
  • Use Case: When a test fails due to race conditions or asynchronous operations, apply this pattern to wait for the actual condition (e.g., element present, API result ready).

Quick Start

Write a test using a condition-based wait instead of a fixed sleep, e.g., replace await sleep(50) with await waitFor(() => isReady(), 'ready state').

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 asynchronous operations and arbitrary delays?

Fix flaky tests by replacing arbitrary setTimeout or sleep delays with condition-based waiting. Use waitFor or polling utilities to wait for actual conditions like element presence or API readiness, ensuring deterministic test outcomes across frontend and backend stacks.

What is the best way to wait for an element or API result in Playwright and Jest?

The best way to wait in Playwright and Jest is using condition-based waiting patterns. Replace fixed sleeps with waitFor utilities that poll for a specific condition, such as an element being present or an API result being ready, to eliminate race conditions.

Can I apply condition-based waiting patterns to Python pytest asynchronous tests?

Yes, condition-based waiting patterns apply to Python pytest asynchronous tests. The language-agnostic concepts help replace arbitrary delays with explicit wait-for conditions, covering TypeScript implementations like Jest and Playwright as well as Python.

Why does my test fail due to race conditions when using sleep or setTimeout?

Tests fail due to race conditions because sleep and setTimeout create timing assumptions rather than verifying state. Replacing arbitrary delays with condition-based waiting checks for actual conditions, preventing timing mismatches and delivering deterministic outcomes.

Does condition-based waiting work for both E2E and unit integration tests?

Yes, condition-based waiting works for E2E and unit integration tests. The pattern applies to asynchronous test scenarios across frontend and backend stacks, satisfying requirements for explicit wait patterns in frameworks like Playwright, Jest, and pytest.