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

Copy to clipboard fails #1153

Closed
robinelvin opened this issue Nov 2, 2023 · 4 comments · Fixed by #1300
Closed

Copy to clipboard fails #1153

robinelvin opened this issue Nov 2, 2023 · 4 comments · Fixed by #1300
Assignees
Labels
bug Something isn't working

Comments

@robinelvin
Copy link

Describe the bug

Using the useCopyToClipboard hook from usehooks-ts in a component makes it fail in testing with happy-dom with the following message:

Copy failed DOMException: Type text/plain does not match the blob's type
    at new ClipboardItem

To Reproduce
Steps to reproduce the behavior:

  1. Create a React component
  2. import usehooks-ts
  3. Use the useCopyToClipboard hook to copy some plain text to the clipboard on a button press for example.
  4. Create a test which uses happy-dom and click the button in the test code
  5. Observe the error

Expected behavior
The string should be copied to the clipboard without error.

Screenshots
If applicable, add screenshots to help explain your problem.

Device:

  • OS: macOS
  • React 18
  • Version 12.10.3
@robinelvin robinelvin added the bug Something isn't working label Nov 2, 2023
@dhruvkelawala
Copy link

Is there no fix for this yet?

@dteoh
Copy link

dteoh commented Dec 7, 2023

I'm not using any hook libs but just a regular navigator.clipboard.writeText(contents) where contents is a string value and it fails.

@andrewdodd
Copy link

I too am having this issue. I am pretty sure it is related to this work: #1116

as when I install 12.7.0 my tests pass fine, and when I install 12.8.0 they fail with this same message ("Type text/plain does not match the blob's type").

capricorn86 added a commit that referenced this issue Mar 12, 2024
… Promise as data type, causing React tests to fail, as testing-library overrides the Clipboard implementation with an implementation relying on Promise as data type
capricorn86 added a commit that referenced this issue Mar 12, 2024
fix: [#1153] Fixes problem with ClipboardItem not supporting text and…
@capricorn86 capricorn86 self-assigned this Mar 12, 2024
@capricorn86
Copy link
Owner

Thank you for reporting @robinelvin, @dhruvkelawala , @dteoh and @andrewdodd! 🙂

The problem should be fixed now:
https://github.com/capricorn86/happy-dom/releases/tag/v13.8.1

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.

5 participants