Stefan
Stefan2mo ago

“TypeError: Illegal constructor” error when using FormData

I'm currently experimenting with the Deno test runner and have set up a simple test. Or at least, I thought I had! When running the test I get the following error:
./tests/async-forms.test.ts (uncaught error)
error: (in promise) TypeError: Illegal constructor
return new FormData(form, submitter);
^
at Module.illegalConstructor (ext:deno_webidl/00_webidl.js:1158:9)
at new FormData (ext:deno_fetch/21_formdata.js:93:14)
at getFormData (file:///home/pepper/Websites/uncluttered/static/get-form-data.ts:8:9)
at file:///home/pepper/Websites/uncluttered/tests/async-forms.test.ts:24:18
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.
./tests/async-forms.test.ts (uncaught error)
error: (in promise) TypeError: Illegal constructor
return new FormData(form, submitter);
^
at Module.illegalConstructor (ext:deno_webidl/00_webidl.js:1158:9)
at new FormData (ext:deno_fetch/21_formdata.js:93:14)
at getFormData (file:///home/pepper/Websites/uncluttered/static/get-form-data.ts:8:9)
at file:///home/pepper/Websites/uncluttered/tests/async-forms.test.ts:24:18
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.
This is the file in which the error occurs: https://codeberg.org/stefanfrede/uncluttered/src/branch/feature/switch-to-deno-test/static/get-form-data.ts This is the test file: https://codeberg.org/stefanfrede/uncluttered/src/branch/feature/switch-to-deno-test/tests/async-forms.test.ts The idea is to test whether my function returns the correct form values. To be honest, I currently have no idea why this error occurs, so I would be very grateful for any suggestions on how to solve it.
6 Replies
Doctor 🤖
Doctor 🤖5w ago
I'd guess this happens because it's inside Deno and it doesn't have a real DOM. Try omitting the submitter argument
bartlomieju
bartlomieju5w ago
It's actually the form argument
bartlomieju
bartlomieju5w ago
According to MDN https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData form should be the DOM element and yeah - Deno doesn't have DOM API support
MDN Web Docs
FormData: FormData() constructor - Web APIs | MDN
The FormData() constructor creates a new FormData object.
bartlomieju
bartlomieju5w ago
@crowlKats any idea how this should work?
crowlKats
crowlKats5w ago
we dont accept any arguments to the constructor since we dont have the DOM. Since the DOM present in the test file us a userspace package, we cant integrate with it.
Stefan
StefanOP4w ago
Thank you for the infos 🙏

Did you find this page helpful?