Skip to content

Commit

Permalink
fix(upload): FileList item function returns file or null instead unde…
Browse files Browse the repository at this point in the history
…fined (#288)
  • Loading branch information
vadimshvetsov committed May 20, 2020
1 parent 1f8ad44 commit 9634863
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
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();
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

0 comments on commit 9634863

Please sign in to comment.