You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using this library with React and Jest, I encountered the following error during test execution:
TypeError: FormData constructor: Argument 1 could not be converted to: undefined.
This occurs when trying to create a FormData object from a ref:
const formRef = useRef(null);
// ...
if (formRef.current) {
const formData = new FormData(formRef.current);
}
<form ref={formRef}>
...
</form>
This works fine in the browser or when using testEnvironment: 'jsdom', but in Jest tests it fails.
Steps to Reproduce
Use useRef(null) to create a form reference and attach that ref to the form.
Attempt to create FormData from formRef.current in a Jest test.
Expected Behavior
FormData should be constructed if formRef.current is a valid form element, or at least the test environment should mimic the browser behavior more closely.
Environment
React version: 19.1.0
Jest version: 29.7.0
Node version: 20.13.1
TryingToImprove, chris-schneider-zen, sknep, gubi995 and jmnsf