testing-library / user-event

🐕 Simulate user events
https://testing-library.com/user-event
MIT License
2.2k stars 249 forks source link

File Input bug when Uploading #1236

Open cjduncana opened 1 month ago

cjduncana commented 1 month ago

Reproduction example

https://codesandbox.io/p/sandbox/test-file-upload-xtg77s

Prerequisites

  1. Have an input element using the file type with an accept attribute with a comma-separated list that adds spaces between each value.
  2. Write a test that uses the upload function on a file that matches one of the latter values in the accept attribute.

Expected behavior

The file input should have the uploaded file.

Actual behavior

The onChange event is not triggered, and the file input doesn't have the uploaded file.

User-event version

^14.1.1

Environment

No response

Additional context

The problem lies in the isAcceptableFile function. After splitting the string by its commas, it doesn't trim the whitespace, so some valid comma-separated tokens fail this test.

cjduncana commented 1 month ago

It's my first time contributing to this project. Once I have time, I can look into how to write an MR following your standards.