Skip to content

Same file upload doesn't fire input event, even when clearing input.value #632

@lucaslcode

Description

@lucaslcode
  • @testing-library/user-event version: 12.8.2
  • Testing Framework and version: jest 26.6.0
  • DOM Environment: jsdom 16.4.0

Relevant code or config

const handleChange = jest.fn();
render(<InputComponent changeHandler={handleChange} />);
const inputEl = screen.getByLabelText("Select file") as HTMLInputElement;
const file = new File([], "image.jpg");
userEvent.upload(inputEl, file);
await waitFor(() => expect(handleChange).toBeCalled());

inputEl.value = "";
userEvent.upload(inputEl, file);
//fails
await waitFor(() => expect(handleChange).toBeCalledTimes(2));

What you did:
In #575, upload was changed so it correctly doesn't fire an onChange/onInput event when the same files are selected. In our use case, we do want it to fire again, and our workaround is adding an onClick event that sets inputEl.value = "".

What happened:
Second input event doesn't fire, even when the value is reset to blank.

Problem description:
Looking at the source, it doesn't appear to take value into account.

Suggested solution:
It should consider the value of the input field, but I'm not sure how the value relates to input.files, which is what is normally used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accuracyImproves the accuracy of how behavior is simulatedenvironment:jsdomIssue with JSDOM environment

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions