refactor(tests): replace fixed waits with dynamic event polling in SuggestionManager tests#275
Merged
bartekplus merged 4 commits intomasterfrom Mar 6, 2026
Merged
Conversation
…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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
waitForNextCall()helper that polls untilgetPredictionmock is called, replacing brittle fixedawait wait(Xms)sleeps before prediction assertionswaitFor()helper for polling arbitrary DOM/state conditions (used for menu visibility checks)await wait(X)+ null-check patterns with the new helpers throughout the test fileawait wait(X)only where genuinely needed: negative assertions (expect no call) and intentional inter-event delaysResult
🤖 Generated with Claude Code