We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm trying to test a piece of code that includes appending a file to a FormData instance, similar to this:
import { assert, expect, test } from "vitest"; export const uploadFile = (data = { files: [] as File[] }): FormData => { const formData = new FormData(); for (const file of data.files) { formData.append("file", file, file.name); } return formData; }; test("should create a correct formdata", () => { const files = [new File([""], "filename", { type: "text/csv" })]; const formdata = uploadFile({ files }); expect(formdata.get("file")).toMatchObject(files[0]); });
Although it works just fine running in Stackblitz, it fails to run locally using node and outputs the following error:
TypeError: Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'
I also tried to use String/Blob types since they are supported in the original FormData spec (according to MDN at least), but without success.
As per discord thread, it seems that node 18 has its own Blob/FormData and so Vitest wont override to use JSDOM polyfills for that.
export default defineConfig({ test: { globals: true, environment: "jsdom", }, });
https://stackblitz.com/edit/vitest-dev-vitest-pv9eck?file=test/basic.test.ts
System: OS: macOS 11.6 CPU: (8) arm64 Apple M1 Memory: 122.02 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 18.8.0 - ~/.nvm/versions/node/v18.8.0/bin/node Yarn: 1.22.15 - /usr/local/bin/yarn npm: 8.18.0 - ~/.nvm/versions/node/v18.8.0/bin/npm Browsers: Chrome: 107.0.5304.87 Firefox: 106.0.2 Safari: 15.2 npmPackages: vitest: ^0.24.5 => 0.24.5
npm
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Describe the bug
I'm trying to test a piece of code that includes appending a file to a FormData instance, similar to this:
Although it works just fine running in Stackblitz, it fails to run locally using node and outputs the following error:
TypeError: Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'
I also tried to use String/Blob types since they are supported in the original FormData spec (according to MDN at least), but without success.
As per discord thread, it seems that node 18 has its own Blob/FormData and so Vitest wont override to use JSDOM polyfills for that.
vite.config.ts
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-pv9eck?file=test/basic.test.ts
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: