I have the following input:
<input
name="name"
type="text"
data-testid="input"
onChange={(e) => setTypedName(e.target.value)}
value=""
/>
the test:
test.only('Should change the value of the input ', async () => {
makeSut()
const nameInput = sut.getByTestId('input') as HTMLInputElement
fireEvent.change(nameInput, { target: { value: 'value' } })
expect(nameInput.value).toBe('value')
})
My assertion fails, as the change does not take effect, while the value remains to be ""
If I remove value="" from the input, change takes effect.
I have tried using fireEvent.input fireEvent.change, userEvent.type and nothing works.
It seems that when I use a default value the testing library does not accept changes, even though it works on production...
Any hints?
Using:
- jest 27.3.1
- @testing-library/react 12.1.2
- @testing-library/user-event 13.5.0