I'm writing tests to click on the value "green" radio button using Jest and React. I am facing an error
Radio Button:
<input id="multicolored" name="colours" type="radio" value="green"> id="radioButton" aria-label="Radio Button" name="radio-button-field">
Radio Test:
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import ReactDOM from 'react-dom';
import Colors from './colors';
import { BrowserRouter } from 'react-router-dom';
test('It should click on radio button', async () => {
const div = document.createElement('div');
const dom = render(
<BrowserRouter>
<Colors />
</BrowserRouter>,
div
);
var input = dom.getByLabelText('Radio Button');
fireEvent.click(input, { target: { value: 'green' } });
});
But I am facing an error. "Unable to fire a "click" event - please provide a DOM element."
Am I missing something or is there another way I can click on radio button using fireEvent?