From b8e73766fe691437f256aebd0dd847f0776056eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E8=88=92=E5=BA=B7?= Date: Sat, 8 Aug 2026 10:26:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E4=BD=9C=E4=B8=BB?= =?UTF-8?q?=E9=A1=B5=E5=8A=A8=E7=94=BB=E6=B5=8B=E8=AF=95=E7=AB=9E=E6=80=81?= =?UTF-8?q?=20(#152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 修复内容 - 隔离角色动作预览测试中的真实帧定时器,避免异步交互期间帧序号偶发漂移。 - 保留 50ms 动画调度与失败帧、重试交互断言。 - 补充 React 中间状态断言的可控定时器约束。 ## 验证 - `npm run test -- src/components/creation-home/CreationLandingView.test.tsx --reporter=dot` - `npm run typecheck` - `npm run check:encoding` - `git diff --check` Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/152 --- docs/technical/【前端测试】React组件测试准则-2026-06-26.md | 3 ++- src/components/creation-home/CreationLandingView.test.tsx | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/technical/【前端测试】React组件测试准则-2026-06-26.md b/docs/technical/【前端测试】React组件测试准则-2026-06-26.md index a2a7667a8..3ae1ea268 100644 --- a/docs/technical/【前端测试】React组件测试准则-2026-06-26.md +++ b/docs/technical/【前端测试】React组件测试准则-2026-06-26.md @@ -1,6 +1,6 @@ # React 组件测试准则 -更新时间:`2026-06-26` +更新时间:`2026-08-07` ## 背景 @@ -36,6 +36,7 @@ - `data-testid` 名称必须描述用户或稳定渲染边界,例如 `image-canvas-editor-snap-guide-vertical`;不要描述 React 私有 state 名称。 - 测试用 fixture 只包含本行为需要的字段。演化中的 payload 使用 `expect.objectContaining(...)` 或 helper 生成默认对象,避免一处契约加字段导致大量无关用例碎裂。 - 当测试是为防止历史回归,应在测试名或邻近注释中说明防的是什么行为,而不是记录实现步骤。 +- 同一用例既要验证定时器调度参数,又要断言确定的中间帧或中间状态时,必须 mock 定时器回调或使用可控假时钟;不得让真实墙上时间在异步交互期间推进被断言的状态,否则本地通过的用例会在较慢 CI 中偶发失败。 ## 试点调整 diff --git a/src/components/creation-home/CreationLandingView.test.tsx b/src/components/creation-home/CreationLandingView.test.tsx index 66647bad8..3bc07b631 100644 --- a/src/components/creation-home/CreationLandingView.test.tsx +++ b/src/components/creation-home/CreationLandingView.test.tsx @@ -480,7 +480,11 @@ describe('CreationLandingView', () => { it('plays a character action on card focus and in the preview dialog', async () => { const user = userEvent.setup(); - const setIntervalSpy = vi.spyOn(window, 'setInterval'); + const setIntervalSpy = vi + .spyOn(window, 'setInterval') + .mockImplementation( + () => 1 as unknown as ReturnType, + ); listEditorProjectsMock.mockResolvedValueOnce(projectItems); listPublicEditorProjectResourcesMock.mockResolvedValueOnce([ {