修复 CreatorPages 回关用例在并发负载下的偶发失败(修 CI flaky) #646

Merged
suzmii merged 1 commits from fix/creator-follow-flaky into master 2026-10-06 15:23:05 +08:00
+7 -2
View File
@@ -138,10 +138,15 @@ it('自己的粉丝支持回关和取消回关,移除须确认且只移除该
total: 1,
});
render(<CreatorConnectionsPage id="a" tab="followers" {...callbacks} />);
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: '移除粉丝' }));