Skip to content

Commit 9634863

Browse files
fix(upload): FileList item function returns file or null instead undefined (testing-library#288)
1 parent 1f8ad44 commit 9634863

File tree

2 files changed

+3
-19
lines changed

2 files changed

+3
-19
lines changed

__tests__/react/upload.js

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { cleanup, render, fireEvent } from "@testing-library/react";
2+
import { cleanup, render } from "@testing-library/react";
33
import "@testing-library/jest-dom/extend-expect";
44
import userEvent from "../../src";
55

@@ -86,14 +86,6 @@ describe("userEvent.upload", () => {
8686
expect(input.files[0]).toStrictEqual(file);
8787
expect(input.files.item(0)).toStrictEqual(file);
8888
expect(input.files).toHaveLength(1);
89-
90-
fireEvent.change(input, {
91-
target: { files: { item: () => {}, length: 0 } },
92-
});
93-
94-
expect(input.files[0]).toBeUndefined();
95-
expect(input.files.item[0]).toBeUndefined();
96-
expect(input.files).toHaveLength(0);
9789
});
9890

9991
it("should upload multiple files", () => {
@@ -113,14 +105,6 @@ describe("userEvent.upload", () => {
113105
expect(input.files[1]).toStrictEqual(files[1]);
114106
expect(input.files.item(1)).toStrictEqual(files[1]);
115107
expect(input.files).toHaveLength(2);
116-
117-
fireEvent.change(input, {
118-
target: { files: { item: () => {}, length: 0 } },
119-
});
120-
121-
expect(input.files[0]).toBeUndefined();
122-
expect(input.files.item[0]).toBeUndefined();
123-
expect(input.files).toHaveLength(0);
124108
});
125109

126110
it("should not upload when is disabled", () => {
@@ -134,7 +118,7 @@ describe("userEvent.upload", () => {
134118
userEvent.upload(input, file);
135119

136120
expect(input.files[0]).toBeUndefined();
137-
expect(input.files.item[0]).toBeUndefined();
121+
expect(input.files.item(0)).toBeNull();
138122
expect(input.files).toHaveLength(0);
139123
});
140124
});

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ const userEvent = {
317317
target: {
318318
files: {
319319
length: files.length,
320-
item: (index) => files[index],
320+
item: (index) => files[index] || null,
321321
...files,
322322
},
323323
},

0 commit comments

Comments
 (0)