DEV Community

Discussion on: Testing a simple component with React Testing Library

Collapse
 
frondor profile image
Federico Vázquez

Nice article! I'd like to add that you should use userEvent.type(input, 'matti') instead of fireEvent.change(input, {target: {value: 'matti'}});.
This way you get a better coverage and also to resemble the user interaction more closely.

Collapse
 
mbarzeev profile image
Matti Bar-Zeev

Thanks!
Yes, I also wrote that there is na option to simulatet the user typing, bit I think that firing the change event is sufficient here. Simulating the actual typing kinda crosses the border between unit and automation test for me, but sure, you can simulate the typing as well.