happy-dom
happy-dom copied to clipboard
Copy to clipboard fails
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:
- Create a React component
- import
usehooks-ts
- Use the
useCopyToClipboard
hook to copy some plain text to the clipboard on a button press for example. - Create a test which uses
happy-dom
and click the button in the test code - 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
Is there no fix for this yet?
I'm not using any hook libs but just a regular navigator.clipboard.writeText(contents)
where contents
is a string value and it fails.
I too am having this issue. I am pretty sure it is related to this work: https://github.com/capricorn86/happy-dom/pull/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").
Thank you for reporting @robinelvin, @dhruvkelawala , @dteoh and @andrewdodd! :slightly_smiling_face:
The problem should be fixed now: https://github.com/capricorn86/happy-dom/releases/tag/v13.8.1