From 52b73b1fd6b50dc928aa5ed00aa157bc99abf2e1 Mon Sep 17 00:00:00 2001 From: Ryan Min <73128364+kcrmin@users.noreply.github.com> Date: Mon, 26 Oct 2026 22:28:03 +0900 Subject: [PATCH] test(strategy): wait for frame-deferred cap focus The editor focuses the cap field in requestAnimationFrame, so asserting focus right after the node appears raced the frame. --- src/BasicEditorInteraction.test.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/BasicEditorInteraction.test.tsx b/src/BasicEditorInteraction.test.tsx index 8427233..e6a0408 100644 --- a/src/BasicEditorInteraction.test.tsx +++ b/src/BasicEditorInteraction.test.tsx @@ -1,4 +1,4 @@ -import { fireEvent, render, screen, within } from '@testing-library/react'; +import { fireEvent, render, screen, waitFor, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { describe, expect, test, vi } from 'vitest'; import { BasicEditor } from './views/StrategyViews'; @@ -523,8 +523,9 @@ describe('Basic editor interactions', () => { const drawer = screen.getByRole('complementary', { name: '전략 오류 안내' }); await user.click(within(drawer).getByRole('button', { name: /AAPL 최대 보유 비율/ })); - const focusedCap = await screen.findByRole('spinbutton', { name: 'AAPL 종목별 최대 보유 비율' }); - expect(focusedCap).toHaveFocus(); + // The editor moves focus inside requestAnimationFrame, so the field can + // exist a frame before it is focused. Wait for focus, not for the node. + await waitFor(() => expect(screen.getByRole('spinbutton', { name: 'AAPL 종목별 최대 보유 비율' })).toHaveFocus()); }); test('allows a complete strategy to launch after block fields and sell percentage are set', async () => {