Description
Reproduction example
https://codesandbox.io/p/sandbox/modest-hermann-pp9wgz
Prerequisites
- Run
userEvent.setup({ writeToClipboard: true })
at the start of a script - Call
navigator.clipboard.writeText("Hello")
- Confirm the text "Hello" has not been copied to the actual clipboard
Expected behavior
When passing writeToClipboard: true
I expect the clipboard stub to copy text to the actual clipboard as normal. Currently it doesn't actually make a difference whether writeToClipboard
is set or not. The property name seems misleading.
This is a problem in Storybook where we instrument user's stories/components with userEvent.setup()
, causing their clipboard behavior to no longer work.
We can work around it by restoring the original clipboard after calling setup()
but that's potentially brittle and does not allow users to leverage the actual stub in their tests. I have attempted to use detachClipboardStub
but that method does not appear to be publicly accessible.
Ideally we would have a clipboard stub that actually calls the real clipboard as well, if possible/available.
Actual behavior
Calling navigator.clipboard.writeText("hello")
is intercepted by user-event's clipboard stub and doesn't forward the call to the actual clipboard API, regardless of the writeToClipboard
option.
User-event version
14.6.1
Environment
Testing Library framework:
JS framework:
Test environment:
DOM implementation:
Additional context
No response