Expose some method add files to a FileList
See original GitHub issueFileList’s are not writeable in the specs, but to make input.files
testable, we’ll need to implement a util method to modify it.
/cc @cpojer
Issue Analytics
- State:
- Created 8 years ago
- Reactions:11
- Comments:33 (11 by maintainers)
Top Results From Across the Web
How to work with FileList (from <input type="file">) in Javascript?
You can use FormData to append Files to a single object. var data = new FormData(); document.querySelector("input[type=file] ...
Read more >The Trouble With Editing And Uploading Files In The Browser
Unfortunately there's no FileList constructor. There is also no “add a file” method exposed on the FileList instance.
Read more >How to Handle File Inputs With JavaScript | by John Au-Yeung
We can trigger a file selection dialog to open with the click method of the file input object. Then we can hide the...
Read more >Dockerfile reference - Docker Documentation
Environment variables are supported by the following list of instructions in the Dockerfile : ADD; COPY; ENV; EXPOSE; FROM; LABEL; STOPSIGNAL ...
Read more >FileList - Web APIs | MDN
An object of this type is returned by the files property of the HTML <input> element; this lets you access the list of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I managed to create FileList without having to alter any of the jsdom library code:
In this case I’m creating FileList object calling constructor on FileList provided by jsdom. After that I’m just adding file to that list using Array notation. In my case I only need 1 File in array but this can also be changed to for loop to add multiple files to FileList. I’m creating file with custom name/type/size through File constructor also provided by jsdom which functionality is following specification.
This might be helpful for someone who is looking how to mock FileList in jsdom environment, but one issue still stands. Creating FileList with array of Files using this method wouldn’t allow getting items from array using FileList.item(index) method. But, even that can be fixed by overriding it’s method something like this:
I still feel it might be better if jsdom could offer these functionalities for testing purposes out of the box.
All modern browsers (i.e. not IE <= 11) now support setting input.files to a FileList https://stackoverflow.com/a/47522812/2744776