Skip to content

feat: add twd.waitFor() polling utility - #212

Merged
kevinccbsg merged 10 commits into
mainfrom
feat/wait-for
Apr 15, 2026
Merged

feat: add twd.waitFor() polling utility#212
kevinccbsg merged 10 commits into
mainfrom
feat/wait-for

Conversation

@kevinccbsg

@kevinccbsg kevinccbsg commented Apr 14, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds twd.waitFor(callback, options?) — a general-purpose retry utility that polls a callback until it stops throwing or the timeout expires (default 2000ms, 50ms interval)
  • Replaces blind twd.wait(ms) calls with condition-based waiting: resolves as soon as the condition is met, making tests faster and more reliable
  • Supports DOM assertions, analytics event checks, and any custom state check — sync or async callbacks

New API

await twd.waitFor(() => {
  const event = findEvent("purchase"); // your analytics helper
  expect(event).to.exist;
}, { message: "purchase event to fire" });

Options: timeout (ms), interval (ms), message (shown in timeout errors).

Test Plan

  • 9 new unit tests in src/tests/utils/waitFor.spec.ts — all passing
  • Full suite: 376 tests across 54 files, all passing
  • TypeScript compilation clean
  • VitePress docs build clean

🤖 Generated with Claude Code

@kevinccbsg
kevinccbsg merged commit f596e4d into main Apr 15, 2026
8 checks passed
@kevinccbsg
kevinccbsg deleted the feat/wait-for branch April 15, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant