Skip to content

test(strategy): wait for frame-deferred cap focus - #186

Open
kcrmin wants to merge 1 commit into
developfrom
test/editor-focus-race
Open

kcrmin wants to merge 1 commit into
developfrom
test/editor-focus-race

Conversation

@kcrmin

@kcrmin kcrmin commented Oct 26, 2026

Copy link
Copy Markdown
Member

What and why

BasicEditorInteraction.test.tsx checked toHaveFocus() right after findByRole returned the position-cap field. StrategyViews.tsx moves focus to that field inside requestAnimationFrame, so the field exists one frame before it is focused and the assertion only passed when the frame happened to fire first.

The test now waits for focus itself with waitFor, which is deterministic regardless of frame timing. No product code changes.

Verified

  • Probe (not committed): with requestAnimationFrame delayed by 60 ms, the old assertion fails and the waitFor assertion passes.
  • pnpm exec vitest run src/BasicEditorInteraction.test.tsx 20 consecutive runs (Node 24): 20 passed, 0 failed (32 tests each)
  • node --test scripts/test-github-action-pins.mjs scripts/test-real-api-integration-workflow.mjs: passed
  • pnpm typecheck: clean
  • pnpm exec vitest run: 58 files, 688 tests passed
  • pnpm build && node scripts/assert-production-bundle.mjs: passed
  • CI=1 pnpm e2e: 26 passed

Checklist

  • Test-only change
  • Assertion still requires the exact invalid field to receive focus
  • Stable across 20 consecutive runs

The editor focuses the cap field in requestAnimationFrame, so asserting
focus right after the node appears raced the frame.
@kcrmin kcrmin mentioned this pull request Oct 27, 2026
4 tasks done
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