Search⌘ K
AI Features

Uploading a File

Explore how to write tests for file uploads in React applications using Jest and React Testing Library. Learn to simulate user actions of selecting single and multiple files, verify success messages, and ensure your upload functionality works as expected through automated testing.

Starter project

The starter project contains an AttachmentForm component, which allows the user to choose and upload a file.

A copy of the project is in the code widget below. Clicking the “Run” button will run the app and display the attachment form.

export default "test-file-stub";
Uploading a file

Run the app.

Select a file and click the “Upload” button. We should see that a success message appears containing the chosen file name:

The project contains a half-implemented test that checks whether a success message appears when an attachment has been selected and uploaded.

Another copy of the project is in the code ...