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: '移除粉丝' }));