From 6f720c36b4ba9d7812f0edcb4f58cc412724e33f Mon Sep 17 00:00:00 2001 From: kdletters Date: Fri, 7 Aug 2026 21:14:21 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 隔离角色动作预览测试的真实帧定时器 补充中间状态断言的定时器测试约束 --- 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 2bd338be4..a37c6bfa0 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([ { -- 2.52.0