MCPcopy Create free account
hub / github.com/testing-library/user-event / createFileList

Function createFileList

src/utils/dataTransfer/FileList.ts:3–28  ·  view source on GitHub ↗
(
  window: Window & typeof globalThis,
  files: File[],
)

Source from the content-addressed store, hash-verified

1// FileList can not be created per constructor.
2
3export function createFileList(
4 window: Window & typeof globalThis,
5 files: File[],
6): FileList {
7 const list: FileList & Iterable<File> = {
8 ...files,
9 length: files.length,
10 item: (index: number) => list[index],
11 [Symbol.iterator]: function* nextFile() {
12 for (let i = 0; i < list.length; i++) {
13 yield list[i]
14 }
15 },
16 }
17 list.constructor = window.FileList
18
19 // guard for environments without FileList
20 /* istanbul ignore else */
21 if (window.FileList) {
22 Object.setPrototypeOf(list, window.FileList.prototype)
23 }
24
25 Object.freeze(list)
26
27 return list
28}

Callers 5

DataTransferStubClass · 0.90
createDataTransferFunction · 0.90
fileDialogFunction · 0.90
FileList.tsFile · 0.90
setFiles.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected