Filling in an input Element
Explore how to simulate user keyboard input and actions in React forms using Jest and React Testing Library. Learn to focus fields, type text, and trigger form submission by pressing keys to create robust user interaction tests.
We'll cover the following...
We'll cover the following...
Starter project
The starter project contains the same ContactForm component as the previous lesson. It also includes a half-implemented test that performs checks on a successful form submission.
A copy of the code is in the code widget below. Click the “Run” button to run the tests.
export default "test-file-stub";
Half-implemented test
Completing the test
There is a keyboard function in the user-event package that simulates a user using the keyboard.
Add the following lines to the test in ContactForm.test.js ...