小编And*_*rtz的帖子

React 测试库 确保在进行新的调用之前等待之前的 act() 调用

我为选择编写了一个测试,并收到此警告。在我的测试中,我正在等待表演结束。为什么我会收到此错误?

警告:您似乎有重叠的 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)

谢谢

unit-testing reactjs testing-library

10
推荐指数
1
解决办法
2万
查看次数

标签 统计

reactjs ×1

testing-library ×1

unit-testing ×1