happy-dom icon indicating copy to clipboard operation
happy-dom copied to clipboard

Copy to clipboard fails

Open robinelvin opened this issue 1 year ago • 3 comments

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 avatar Nov 02 '23 13:11 robinelvin

Is there no fix for this yet?

dhruvkelawala avatar Nov 29 '23 05:11 dhruvkelawala

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

dteoh avatar Dec 07 '23 05:12 dteoh

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").

andrewdodd avatar Jan 24 '24 09:01 andrewdodd

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

capricorn86 avatar Mar 12 '24 12:03 capricorn86