input type="file" - upload() doesn't trigger onChange in React
See original GitHub issue@testing-library/user-eventversion: 12.0.0+- Testing Framework and version: jest@26.1.0
- DOM Environment: jsdom@16.2.2
Relevant code or config:
All relevant code is in the codesandbox, no special config needed.
What you did:
I have a project with a form that includes a <input type="file"/>. I wrote a test for the form that was working well up until I upgraded from v11 to v12. I created a simple codesandbox that reproduces the issue.
The repro includes a simple form with just the relevant input element and a form clear button because the value is read-only and I wanted to make sure the test is clean. The test calls userEvent.upload to upload a fake file and checks if the callback inside of onChange was called.
What happened:
In the small repro sandbox the test is passing on v11 (11.4.2 specifically, which is the latest) but fails on 12.0.0.

Reproduction repository:
https://codesandbox.io/s/testing-library-user-event-file-input-change-event-728w8
Problem description:
In React, onChange is not triggered when using userEvent.upload(...) to add a file to a <input type="file"/>.
When I came to file this issue I found this similar issue that already has a merged fix PR so I suspect the solution should be pretty straight forward requiring a similar for upload as was changed for selectOptions. Considering this is the second function that broke in the same way, it’s probably worth it to check if there are more similar cases as well.
Suggested solution:
The solution should be very similar to this merged PR. I can try to get a PR for it this evening but I figured I’d file the issue now in case someone else can get it done earlier.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)

Top Related StackOverflow Question
I am still having this issue.
Pull request would be appreciated 👍👍