Im having a problem with a query, I'm trying to get two radio inputs, I don't have any problem with one of them, but with the other one React Testing Library thrown an error: It Found multiple elements with the role "radio" and name /to/i:
queries
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 button must be
// disabled
expect(continueButton).toBeDisabled();
});
Html structure
<label for="transferFunds_from" class="ant-form-item-required" title="From">From</label>
<input id="transferFunds_from" type="radio" class="ant-radio-button-input" value="">
<label for="transferFunds_to" class="ant-form-item-required" title="To">To</label>
<input id="transferFunds_to" type="radio" class="ant-radio-button-input" value="">
Error thrown by RTL
TestingLibraryElementError: Found multiple elements with the role "radio" and name `/to/i`
Here are the matching elements:
<input
class="ant-radio-button-input"
id="transferFunds_from"
type="radio"
value=""
/>
<input
class="ant-radio-button-input"
id="transferFunds_to"
type="radio"
value=""
/>
I don't know if I'm doing something wrong in the HTML structure or if it's a React Testing Library error.
getByRole
and there's multiple elements, yet I don't see that called anywhere – Rociorock