Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion code/core/src/test/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,19 @@ const enhanceContext: LoaderFunction = async (context) => {

// userEvent.setup() cannot be called in non browser environment and will attempt to access window.navigator.clipboard
// which will throw an error in react native for example.
if (globalThis.window?.navigator?.clipboard) {
const { clipboard } = globalThis.window?.navigator;
if (clipboard) {
context.userEvent = instrument(
{ userEvent: uninstrumentedUserEvent.setup() },
{ intercept: true }
).userEvent;

// Restore original clipboard, which was replaced with a stub by userEvent.setup()
Object.defineProperty(globalThis.window.navigator, 'clipboard', {
get: () => clipboard,
configurable: true,
});

let currentFocus = HTMLElement.prototype.focus;

if (!patchedFocus) {
Expand Down
Loading