Can't seem to get the value of an input using react-testing library, but for some reason one can set a value via fireEvent
. nameInput
is an actual input element
test('verify name validation works', () => {
const { getByPlaceholderText, getByTestId, debug } = render(<Home/>)
const passForm = getByTestId('form')
const nameInput = getByPlaceholderText('Name');
fireEvent.change(nameInput, { target: { value: 'TestName' }});
debug(nameInput.value) // error
})
Update
I have to assert as HTMLInputElement
to work as ts inferring it as a generic HTMLElement
expect((nameInput as HTMLInputElement).value)
input
? otherwise thechange
will not really update the input value. – Ignace