Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(upload): accept File or File[] #529 #530

Merged
merged 1 commit into from Jan 21, 2021
Merged

fix(upload): accept File or File[] #529 #530

merged 1 commit into from Jan 21, 2021

Conversation

ph-fritsche
Copy link
Member

@ph-fritsche ph-fritsche commented Dec 22, 2020

What:

const f = new File(/*...*/)

// these two will be equivalent
userEvent.upload(element, [f])
userEvent.upload(element, f)

Why:

Previous implementation required the user to provide File for single file inputs and File[] for multiple file inputs.

How:

Convert to an array if it is not.
Truncate to length 1 if input is not multiple.

Checklist:

  • Documentation
  • Tests
  • Typings N/A
  • Ready to be merged

@codecov
Copy link

codecov bot commented Dec 22, 2020

Codecov Report

Merging #530 (f645798) into master (6c21e1f) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #530   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           13        13           
  Lines          675       675           
  Branches       211       213    +2     
=========================================
  Hits           675       675           
Impacted Files Coverage Δ
src/upload.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c21e1f...f645798. Read the comment docs.

@kentcdodds
Copy link
Member

I'm not sure I understand the motivation for this change.

Previous implementation required the user to provide File for single file inputs and File[] for multiple file inputs.

I think that's sensible and expected. I'm what situation would I want to pass an array for a single or a single file for a multiple?

@ph-fritsche
Copy link
Member Author

I think that's sensible and expected. I'm what situation would I want to pass an array for a single or a single file for a multiple?

As #529 demonstrated people get confused why their file input won't accept the file upload.

And I like the thought of being as agnostic as possible about implementation details.
If someone has a file input that changes to multiple a test where someone tries to upload a file to it should not fail.
If a file input changes away from multiple a test trying to e.g. drag&drop one file should still pass and one where he drags two files should fail because the second file gets lost not because of syntactic errors.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Thanks!

@kentcdodds kentcdodds merged commit 390013e into master Jan 21, 2021
@kentcdodds kentcdodds deleted the fix-529 branch January 21, 2021 16:09
@github-actions
Copy link

🎉 This PR is included in version 12.6.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants