question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

input type="file" - upload() doesn't trigger onChange in React

See original GitHub issue
  • @testing-library/user-event version: 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.

image

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:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tmanundercovercommented, Oct 4, 2021

I am still having this issue.

1reaction
kentcdoddscommented, Jun 24, 2020

Pull request would be appreciated 👍👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

React input type file onChange not firing - Stack Overflow
I've tried using react-file-reader-input and react-file-reader , and just a raw input tag like in the snippet. None of them fire the onChange...
Read more >
Choosing the same file doesn't trigger onChange #11 - GitHub
Here is my scenario using similar markup as the readme: Click "Select a file!" button and select house.jpg . This triggers onChange, everything ......
Read more >
[Solved]-React input type file onChange not firing-Reactjs
[Solved]-React input type file onChange not firing-Reactjs. It's by design in Chrome. Set value to empty string and store the file in useState()...
Read more >
Second use of input file doesn't trigger onchange anymore
Here is a use case: 1. On click of the button, I call uploadMessagePicture(), which opens the browse window. 2. When the user...
Read more >
Input File change event not working - EncodeDna.com
A simple solution to get rid of this issue will be, to clear the file input value. I'll show you how. Let's see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found