I'm currently running some tests for a project I'm working on, and am having trouble using fireEvent.select()
as a way to focus on an input field.
My test so far:
it('is not working :(', () => {
const input = queryByPlaceholderText('blah');
fireEvent.change(input, {
target: {value: 'some text'},
});
expect(input).toHaveAttribute('value', 'some text');
fireEvent.select(input); <-- issue here
});
The component I am testing has a dropdown menu that is only exposed when the input is focused on, but it seems like neither fireEvent.change()
nor fireEvent.select()
are focusing on the field. I know that fireEvent.change()
changes the input value.
So far, I have tried:
fireEvent.click()
fireEvent.focus()
fireEvent.select()
input.focus()
but none of those options worked.
I need to be able to select an option in this dropdown menu to be able to properly test the component.
TL;DR
Is there a way to focus on an input field with RTL?