Skip to content
New issue

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

TypeError: The "obj" argument must be an instance of Blob. Received an instance of File vitest #847

Closed
mirzaahmedov opened this issue Apr 8, 2023 · 3 comments · Fixed by #1086
Assignees
Labels
bug Something isn't working

Comments

@mirzaahmedov
Copy link

Describe the bug
I am trying to test file upload functionality but getting this error

this.form[name] = URL.createObjectURL(e.target.files[0])

test

userEvent.upload(input, file)

gives me this error TypeError: The "obj" argument must be an instance of Blob. Received an instance of File Vitest

Additional context
I am using Vitest with happy-dom

@mirzaahmedov mirzaahmedov added the bug Something isn't working label Apr 8, 2023
@btea
Copy link
Contributor

btea commented Apr 10, 2023

This seems to be a problem with nodejs, only values ​​of type Blob are supported. reference documents

@capricorn86
Copy link
Owner

capricorn86 commented Apr 11, 2023

I think we will have to extend NodeJS:s URL with our own implementation for methods that depends on Happy DOM classes such as File and Blob.

import { URL as NodeJSURL } from 'url';

export default class URL extends NodeJSURL {
       public override createObjectURL(object: Blob): string {
              // TODO: Implement
       }
}

The alternative way is to use NodeJS:s Blob object, but that has downsides such as decreased performance (as it is not possible to access its internal buffer).

@capricorn86 capricorn86 self-assigned this Sep 22, 2023
capricorn86 added a commit that referenced this issue Sep 22, 2023
capricorn86 added a commit that referenced this issue Sep 22, 2023
…argument-must-be-an-instance-of-blob-received-an-instance-of-file-vitest

#847@patch: Fixes bug in URL.createObjectURL() where it did not suppo…
@capricorn86
Copy link
Owner

A fix has now been released 🙂

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v12.1.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants