Closed ldm-acn closed 18 hours ago
This looks like a jsdom issue since it works on happy-dom. You would probably need to report it there to see if this is supported. https://stackblitz.com/edit/stackblitz-starters-mzb5tx?file=components%2FForm.tsx
Btw, it looks like new FormData(e.currentTarget)
is working for both.
stdout | components/jsdom.test.tsx > repro jsdom
[handleSubmit] field.value = undefined
[FormData.entries] { field: 'abc123' }
stdout | components/happy-dom.test.tsx > repro happy-dom
[handleSubmit] field.value = abc123
[FormData.entries] { field: 'abc123' }
Link to the jsdom issue: https://github.com/jsdom/jsdom/issues/3715
Closing this as I don't see any reason to keep this open in Vitest.
Describe the bug
Testing a component that contains a form with Vitest and React Testing Library in a Next project leads to a submit event that doesn't contain the input elements that are part of the form itself.
Reproduction
I recreated the issue with a minimal example here
If you try to interact with the form from the ui preview you should see the input field content be printed to the console.
If you try to run
npm run test
you'll see an error becauseevent.currentTarget
doesn't contain an element called "field".System Info
Used Package Manager
pnpm
Validations