testing-library / testing-library/user-event

Can't test "file" type inputs.

Open
#1,203 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.3k
Forks
258
PR merge metrics
No merged PRs in 30d

Description

Environment
  • @testing-library/react version: 14.2.1
  • Testing Framework and version:
    react-scripts version: 5.0.1
  • DOM Environment:
    jsdom from react-scripts
Reproduction:

Minimal reproduction on CodeSandbox: here

What you did:

I need to assert that my api is receiving the correct files. In this minimal reproduction it might not make sense because it's like I am testing DOM, but in my real world scenario the form is more complex and in that context this test makes sense.

What happened:

when I call
expect(api).toHaveBeenCalledWith({name: "hello.txt", file: file})
I receive {name: "", file: {}}.

Basically I am unable to assert what file was passed in the function.

Thank you.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and inspect how the file input interaction reaches the API call. Reproduce the {name: "", file: {}} result, then trace the user-event file-input path and its tests. Done means the selected file's name and file object are preserved so the shown assertion can pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react, typescript
Domain
frontend, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.