我为选择编写了一个测试,并收到此警告。在我的测试中,我正在等待表演结束。为什么我会收到此错误?
警告:您似乎有重叠的 act() 调用,这是不支持的。在进行新的调用之前,请务必等待之前的 act() 调用。
test('Selection should be have the correct number of options', async () => {
const leftClick = { button: 0 };
const { options } = makeSUT();
const selection = screen.getByLabelText('MultiSelection');
// open all option
act(() => {
userEvent.click(selection, leftClick);
});
// await wait();
options.forEach(async (option, index) => {
if (index === 0) {
expect((await screen.findAllByText(option.label)).length).toEqual(1);
} else {
expect((await screen.findAllByText(option.label)).length).toEqual(1);
}
});
});
Run Code Online (Sandbox Code Playgroud)
谢谢