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): FileList item function must return null instead undefined when it can't find a file #288

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 2 additions & 18 deletions __tests__/react/upload.js
@@ -1,5 +1,5 @@
import React from "react";
import { cleanup, render, fireEvent } from "@testing-library/react";
import { cleanup, render } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import userEvent from "../../src";

Expand Down Expand Up @@ -86,14 +86,6 @@ describe("userEvent.upload", () => {
expect(input.files[0]).toStrictEqual(file);
expect(input.files.item(0)).toStrictEqual(file);
expect(input.files).toHaveLength(1);

fireEvent.change(input, {
target: { files: { item: () => {}, length: 0 } },
});

expect(input.files[0]).toBeUndefined();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This tests do nothing special to user-event library. They only checks that fireEvent function works properly.

expect(input.files.item[0]).toBeUndefined();
expect(input.files).toHaveLength(0);
});

it("should upload multiple files", () => {
Expand All @@ -113,14 +105,6 @@ describe("userEvent.upload", () => {
expect(input.files[1]).toStrictEqual(files[1]);
expect(input.files.item(1)).toStrictEqual(files[1]);
expect(input.files).toHaveLength(2);

fireEvent.change(input, {
target: { files: { item: () => {}, length: 0 } },
});

expect(input.files[0]).toBeUndefined();
expect(input.files.item[0]).toBeUndefined();
expect(input.files).toHaveLength(0);
});

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

expect(input.files[0]).toBeUndefined();
expect(input.files.item[0]).toBeUndefined();
expect(input.files.item(0)).toBeNull();
expect(input.files).toHaveLength(0);
});
});
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -317,7 +317,7 @@ const userEvent = {
target: {
files: {
length: files.length,
item: (index) => files[index],
item: (index) => files[index] || null,
...files,
},
},
Expand Down