condition-based-waiting

Replace arbitrary timeouts in asynchronous tests with condition polling.

Updated Mar 13, 2026
One-click install
npx skills add https://github.com/kirvin/copilot-cli-essentials --skill condition-based-waiting-kirvin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/kirvin/copilot-cli-essentials/tree/main/plugins/cpe/skills/condition-based-waiting
Command: npx skills add https://github.com/kirvin/copilot-cli-essentials --skill condition-based-waiting-kirvin

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses flaky tests caused by arbitrary timeouts and race conditions, ensuring more reliable test suites by replacing guesswork with condition-based polling.

Core Features & Use Cases

  • Replace setTimeout/sleep: Swap fixed delays with checks for actual conditions.
  • Framework Integration: Leverages built-in waiting mechanisms in popular testing frameworks (Testing Library, Playwright, pytest).
  • Custom Polling: Provides a fallback pattern for custom polling logic when framework utilities are insufficient.
  • Use Case: Your integration tests intermittently fail because a UI element isn't visible yet. Instead of adding a sleep(2), use this skill to wait until the element is actually visible or interactive.

Quick Start

Use the condition-based-waiting skill to replace arbitrary timeouts in your tests with condition polling.

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 arbitrary timeouts and race conditions?

Fix flaky tests by replacing fixed timeouts with condition polling for asynchronous operations. This approach checks for actual UI visibility or state conditions, eliminating intermittent timing failures without guesswork.

What's the best way to wait for a UI element to appear instead of using sleep?

The best way to wait for a UI element is using condition polling instead of sleep. You replace fixed delays with checks for actual conditions, waiting until the element is actually visible or interactive before proceeding.

Does this condition polling approach work with Playwright and Testing Library?

Yes, condition polling works with Playwright and Testing Library by leveraging their built-in waiting mechanisms. Playwright offers auto-waiting, and Testing Library provides `waitFor`, with custom polling functions as a fallback.

How do I implement custom polling logic when framework utilities are insufficient?

Implement custom polling logic by writing a fallback polling function that repeatedly checks for a specific condition. This pattern replaces arbitrary timeouts when built-in framework utilities like Playwright's auto-waiting are insufficient.

Why do my integration tests intermittently fail due to timing issues?

Integration tests intermittently fail due to timing issues because arbitrary timeouts and race conditions cause asynchronous operations to resolve unpredictably. Replacing fixed delays with condition-based polling ensures tests wait for actual states.

When should I not use condition-based waiting in my test suite?

You should avoid condition-based waiting when testing synchronous code or operations with deterministic timing. It targets asynchronous execution and intermittent UI failures, so deterministic tests may not benefit from condition polling overhead.