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

FileReader never throws errors #1565

Closed
tpuida opened this issue Oct 15, 2024 · 0 comments · Fixed by #1575
Closed

FileReader never throws errors #1565

tpuida opened this issue Oct 15, 2024 · 0 comments · Fixed by #1575
Labels
bug Something isn't working

Comments

@tpuida
Copy link

tpuida commented Oct 15, 2024

Describe the bug

const reader = new FileReader();
reader.readAsDataURL(file);

reader.onload = function () {
  resolve(reader.result);
  };
reader.onerror = function (error) {
  reject(error); // never goes here
};

The following test failed:

it('should reject with an error when passed an invalid file', async () => {
    const invalidFile = {};
    await expect(fileToBase64(invalidFile)).rejects.toThrowError();
  });
  
  - Expected: 
[Error: rejected promise]

+ Received: 
"data:application/octet-stream;base64,"

Expected behavior
To throw an error. For example, Mozilla throws the error:
Uncaught TypeError: FileReader.readAsDataURL: Argument 1 does not implement interface Blob.

Screenshots

Device:

  • OS: MacOS 14.6.1
  • Browser Mozilla
  • Version 15.7.4

Additional context
Vitest tests.
The test provided passes on jsdom environment

@tpuida tpuida added the bug Something isn't working label Oct 15, 2024
btea added a commit to btea/happy-dom that referenced this issue Nov 2, 2024
btea added a commit to btea/happy-dom that referenced this issue Nov 2, 2024
capricorn86 added a commit to btea/happy-dom that referenced this issue Nov 6, 2024
…tionObserver can then detect the origin of the error
capricorn86 added a commit to btea/happy-dom that referenced this issue Nov 6, 2024
capricorn86 added a commit that referenced this issue Nov 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…sArrayBuffer, FileReader.readAsBinaryString, FileReader.readAsDataURL and FileReader.readAsText (#1575)

* fix: [#1565] Strictly check the type of `blob` parameters

* chore: [#1565] Uses TypeError from Window, as BrowserExceptionObserver can then detect the origin of the error

* chore: [#1565] Fixes linting error

---------

Co-authored-by: David Ortner <david@ortner.se>
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.

1 participant