From 3b99da832f95793b095de69384cc57fe9042179d Mon Sep 17 00:00:00 2001 From: Suzumiya Date: Tue, 6 Oct 2026 15:03:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20CreatorPages=20=E5=9B=9E?= =?UTF-8?q?=E5=85=B3=E7=94=A8=E4=BE=8B=E5=9C=A8=E5=B9=B6=E5=8F=91=E8=B4=9F?= =?UTF-8?q?=E8=BD=BD=E4=B8=8B=E7=82=B9=E5=87=BB=E8=A2=AB=E5=90=9E=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E5=81=B6=E5=8F=91=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在「自己的粉丝支持回关和取消回关,移除须确认且只移除该行」用例中,先取到「回关」按钮并保留引用,不再取到后立即同步点击 - 新增等待该按钮 disabled 变为 false 再 fireEvent.click,避免关系 store 尚未 seed、按钮仍是 disabled 时 React 不派发 onClick 而把这次点击吞掉 - 补充简短中文注释,说明行首帧早于关系 store seed、必须等按钮可用再点 --- src/components/creator/CreatorPages.test.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/creator/CreatorPages.test.tsx b/src/components/creator/CreatorPages.test.tsx index f48f8a53a..2db17b131 100644 --- a/src/components/creator/CreatorPages.test.tsx +++ b/src/components/creator/CreatorPages.test.tsx @@ -138,10 +138,15 @@ it('自己的粉丝支持回关和取消回关,移除须确认且只移除该 total: 1, }); render(); - await screen.findByRole('button', { name: '回关' }); + // 关系 store 的 seed 晚于行首帧,此时按钮仍是 disabled;React 不会对 disabled + // 元素派发 onClick,必须先等到按钮可用再点,否则这次点击会被直接吞掉。 + const back = (await screen.findByRole('button', { + name: '回关', + })) as HTMLButtonElement; + await waitFor(() => expect(back.disabled).toBe(false)); api.write.mockResolvedValue({ relationship: following }); api.list.mockResolvedValue({ items: [row()], nextCursor: null, total: 1 }); - fireEvent.click(screen.getByRole('button', { name: '回关' })); + fireEvent.click(back); await screen.findByRole('button', { name: '取消关注' }); expect(api.write).toHaveBeenLastCalledWith('b', 'follow'); fireEvent.click(screen.getByRole('button', { name: '移除粉丝' }));