Configure Vitest in non-globals mode (the default)
Call userEvent.setup() in a test
Copy something to the clipboard in a test
Inspect the clipboard in a later test
Expected behavior
Clipboard state should be reset between tests, or there should be a documented way to add that clipboard cleanup to one's suite.
Without globals mode, I see a couple possible solutions. Adding one or both of these would be appropriate, I think:
The module should export cleanup functions from the root (like other @testing-library modules) so a user can add cleanup to their test hooks manually
Calling userEvent.setup should reset clipboard stub state
Actual behavior
Clipboard stub state is retained between tests
User-event version
14.5.2
Environment
No response
Additional context
Let me know if you need any assistance resolving this bug! I maintain @testing-library/svelte and I'm happy to jump in here, too, if it's helpful
As a workaround - since I'm not willing to enable globals mode - I am currently adding this to my global test setup file. It's not pretty, obvious, nor documented, so it would be nice if user-event could provide a blessed way to do this in Vitest
Reproduction example
https://codesandbox.io/p/github/mcous/user-event-clipboard-leak/main?import=true
Prerequisites
userEvent.setup()
in a testExpected behavior
Clipboard state should be reset between tests, or there should be a documented way to add that clipboard cleanup to one's suite.
Without globals mode, I see a couple possible solutions. Adding one or both of these would be appropriate, I think:
@testing-library
modules) so a user can add cleanup to their test hooks manuallyuserEvent.setup
should reset clipboard stub stateActual behavior
User-event version
14.5.2
Environment
No response
Additional context
Let me know if you need any assistance resolving this bug! I maintain
@testing-library/svelte
and I'm happy to jump in here, too, if it's helpfulAs a workaround - since I'm not willing to enable globals mode - I am currently adding this to my global test setup file. It's not pretty, obvious, nor documented, so it would be nice if
user-event
could provide a blessed way to do this in Vitest