vitest-dev / vitest-dev/vitest
form data file name not being preserved through a request in jsdom
Open
@sheremet-va is already working on this.
Since Jan 5, 2026.
pending triage
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 94
Description
Describe the bug
When a file name is given to a File object and attached to a Request through a FormData object, the file name given is lost.
I've tracked the issue down to this line of code
where it doesn't copy over the file name if there is one. It is likely that this line was intended to only execute this code for Blobs, but File is a subclass of Blob.
Reproduction
test("file name preserves through a request", async () => {
const fileName = "my-doc.pdf"
const file = new File([new Uint8Array(1_024)], fileName, {
type: "application/pdf",
})
const formData = new FormData()
formData.append("file", file, fileName)
const request = new Request("http://example.com", {
body: formData,
method: "POST",
})
const result = await request.formData()
expect(result.get("file").name).toEqual(fileName)
})
System Info
System:
OS: Linux 5.15 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
CPU: (8) x64 AMD EPYC 7R13 Processor
Memory: 27.18 GB / 30.67 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 24.12.0 - /home/coder/.nvm/versions/node/v24.12.0/bin/node
npm: 11.6.2 - /home/coder/.nvm/versions/node/v24.12.0/bin/npm
npmPackages:
@vitejs/plugin-react: ^5.1.2 => 5.1.2
@vitest/coverage-v8: ^4.0.15 => 4.0.15
vite: ^7.2.7 => 7.3.0
vitest: ^4.0.15 => 4.0.15
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.