Skip to content

refactor(tests): replace fixed waits with dynamic event polling in SuggestionManager tests#275

Merged
bartekplus merged 4 commits intomasterfrom
test/dynamic-wait-suggestion-manager
Mar 6, 2026
Merged

refactor(tests): replace fixed waits with dynamic event polling in SuggestionManager tests#275
bartekplus merged 4 commits intomasterfrom
test/dynamic-wait-suggestion-manager

Conversation

@bartekplus
Copy link
Owner

Summary

  • Add waitForNextCall() helper that polls until getPrediction mock is called, replacing brittle fixed await wait(Xms) sleeps before prediction assertions
  • Add waitFor() helper for polling arbitrary DOM/state conditions (used for menu visibility checks)
  • Replace ~30 inline await wait(X) + null-check patterns with the new helpers throughout the test file
  • Keep await wait(X) only where genuinely needed: negative assertions (expect no call) and intentional inter-event delays

Result

  • 69 insertions / 179 deletions (net -110 lines)
  • Tests are faster when predictions resolve quickly and more reliable when they take longer
  • All 60 tests pass

🤖 Generated with Claude Code

…ggestionManager tests

Replace brittle `await wait(Xms)` calls with `waitForNextCall()` and `waitFor()` helpers
that poll for observable state changes instead of sleeping a fixed duration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bartekplus bartekplus self-assigned this Mar 6, 2026
bartekplus and others added 3 commits March 6, 2026 22:48
Add curly braces to single-line if statements (eslint curly rule) and
auto-format with prettier. Also exclude .claude/ from prettier checks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add withFakeTimers() helper that wraps jest.useFakeTimers() +
advanceTimersByTime() + useRealTimers() for negative assertion tests
(asserting getPrediction is NOT called). Remove the now-unused wait()
helper. Suite runs in ~6.8s vs ~9.6s before.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When `restart()` schedules a `setTimeout(..., 0)`, calling `disable()` (e.g.
via `destroy()`) did not cancel that timer. The leaked timer could fire during
the next test's async module import, inserting a stale SuggestionManager
instance into the shared harness and causing intermittent test failures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bartekplus bartekplus merged commit 7e877ca into master Mar 6, 2026
8 checks passed
@bartekplus bartekplus deleted the test/dynamic-wait-suggestion-manager branch March 6, 2026 22: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