相关疑难解决方法(0)

在 React 测试库中发现多个元素错误

我在查询时遇到问题,我正在尝试获取两个无线电输入,其中之一没有任何问题,但另一个反应测试库引发了错误:It Found multiple elements with the role "radio" and name /to/i:

查询

test('Render form with default items', () => {
  const handleUpdateValue = jest.fn();
  const handleNextStep = jest.fn();
  render(
    <Form
      handleNextStep={handleNextStep}
      updateValue={handleUpdateValue}
      transferFundsValues={{}}
    />
  );

  const amountInput = screen.getByLabelText(/amount/i);
  const fromRadio = screen.getByLabelText(/from/i);
  const toRadio = screen.getByLabelText(/to/i);
  const messageInput = screen.getByLabelText(/message/i);

  const continueButton = screen.getByRole('button', { name: /continue/i });
  const cancelButton = screen.getByRole('button', { name: /cancel/i });

  // If no value has been entered to the inputs, the continue …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs react-testing-library

36
推荐指数
4
解决办法
7万
查看次数