File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -92,12 +92,19 @@ const enhanceContext: LoaderFunction = async (context) => {
92
92
93
93
// userEvent.setup() cannot be called in non browser environment and will attempt to access window.navigator.clipboard
94
94
// which will throw an error in react native for example.
95
- if ( globalThis . window ?. navigator ?. clipboard ) {
95
+ const clipboard = globalThis . window ?. navigator ?. clipboard ;
96
+ if ( clipboard ) {
96
97
context . userEvent = instrument (
97
98
{ userEvent : uninstrumentedUserEvent . setup ( ) } ,
98
99
{ intercept : true }
99
100
) . userEvent ;
100
101
102
+ // Restore original clipboard, which was replaced with a stub by userEvent.setup()
103
+ Object . defineProperty ( globalThis . window . navigator , 'clipboard' , {
104
+ get : ( ) => clipboard ,
105
+ configurable : true ,
106
+ } ) ;
107
+
101
108
let currentFocus = HTMLElement . prototype . focus ;
102
109
103
110
if ( ! patchedFocus ) {
You can’t perform that action at this time.
0 commit comments