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

feat(upload)!: replace element properties #794

Merged
merged 1 commit into from
Nov 25, 2021
Merged

Conversation

ph-fritsche
Copy link
Member

@ph-fritsche ph-fritsche commented Nov 25, 2021

BREAKING CHANGE: init parameter has been removed from userEvent.upload.

What:

  1. Replace properties on <input type="file"/> when changing it per userEvent.upload.
  2. Remove init parameter.

Why:

The previous implementation changed the element.files properties through fireEvent and event.target.files.
That assigns the given property to the element.
As a result the element's value, type and files properties don't interact with each other any more like they do in the browser.

The init parameter has been removed for MouseEvent and there is no good reason to keep it here. See #784

How:

We can not programmatically create a FileList.
The browser creates these from trusted events and both the browser and Jsdom prevent constructing it and also prevent calling the FileList prototype methods on an object which was not created by their internal mechanism.
They also prevent setting element.files to a value that is not a real FileList.

This PR therefore introduces a utility that, given one of our FileList stubs, replaces the relevant property descriptors on the element and mimicks the browser behavior.

Checklist:

  • Documentation
  • Tests
  • Ready to be merged

BREAKING CHANGE: `init` parameter has been removed from `userEvent.upload`.
@ph-fritsche ph-fritsche added this to the userEvent v14 milestone Nov 25, 2021
@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit f3e6228:

Sandbox Source
userEvent-PR-template Configuration

@codecov
Copy link

codecov bot commented Nov 25, 2021

Codecov Report

Merging #794 (f3e6228) into alpha (df75e5f) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             alpha      #794   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           76        77    +1     
  Lines         1547      1568   +21     
  Branches       572       576    +4     
=========================================
+ Hits          1547      1568   +21     
Impacted Files Coverage Δ
src/setup/directApi.ts 100.00% <100.00%> (ø)
src/utility/upload.ts 100.00% <100.00%> (ø)
src/utils/dataTransfer/FileList.ts 100.00% <100.00%> (ø)
src/utils/edit/setFiles.ts 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 df75e5f...f3e6228. Read the comment docs.

@ph-fritsche ph-fritsche merged commit 4873895 into alpha Nov 25, 2021
@ph-fritsche ph-fritsche deleted the feat-uploadinit branch November 25, 2021 20:24
@github-actions
Copy link

🎉 This PR is included in version 14.0.0-alpha.17 🎉

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant