@@ -4,7 +4,14 @@ import {prepareDocument} from './document'
4
4
import { hover , unhover } from './hover'
5
5
import { createKeyboardState , keyboard , keyboardOptions } from './keyboard'
6
6
import type { keyboardState } from './keyboard/types'
7
- import { paste , pasteOptions } from './paste'
7
+ import {
8
+ copy ,
9
+ copyOptions ,
10
+ cut ,
11
+ cutOptions ,
12
+ paste ,
13
+ pasteOptions ,
14
+ } from './clipboard'
8
15
import { createPointerState , pointer } from './pointer'
9
16
import type { pointerOptions , pointerState } from './pointer/types'
10
17
import { deselectOptions , selectOptions } from './selectOptions'
@@ -16,6 +23,8 @@ import {PointerOptions, attachClipboardStubToView} from './utils'
16
23
export const userEventApis = {
17
24
clear,
18
25
click,
26
+ copy,
27
+ cut,
19
28
dblClick,
20
29
deselectOptions,
21
30
hover,
@@ -37,6 +46,8 @@ export type UserEvent = UserEventApis & {
37
46
38
47
type ClickOptions = Omit < clickOptions , 'clickCount' >
39
48
49
+ interface ClipboardOptions extends copyOptions , cutOptions , pasteOptions { }
50
+
40
51
type KeyboardOptions = Partial < keyboardOptions >
41
52
42
53
type PointerApiOptions = Partial < pointerOptions >
@@ -52,6 +63,7 @@ type UploadOptions = uploadOptions
52
63
53
64
interface SetupOptions
54
65
extends ClickOptions ,
66
+ ClipboardOptions ,
55
67
KeyboardOptions ,
56
68
PointerOptions ,
57
69
PointerApiOptions ,
@@ -88,6 +100,13 @@ function _setup(
88
100
skipClick,
89
101
skipHover,
90
102
skipPointerEventsCheck = false ,
103
+ // Changing default return type from DataTransfer to Promise<DataTransfer>
104
+ // would require a lot of overloading right now.
105
+ // The APIs returned by setup will most likely be changed to async before stable release anyway.
106
+ // See https://github.com/testing-library/user-event/issues/504#issuecomment-944883855
107
+ // So the default option can be changed during alpha instead of introducing too much code here.
108
+ // TODO: This should default to true
109
+ writeToClipboard = false ,
91
110
} : SetupOptions ,
92
111
{
93
112
keyboardState,
@@ -118,8 +137,9 @@ function _setup(
118
137
const clickDefaults : clickOptions = {
119
138
skipHover,
120
139
}
121
- const clipboardDefaults : pasteOptions = {
140
+ const clipboardDefaults : ClipboardOptions = {
122
141
document,
142
+ writeToClipboard,
123
143
}
124
144
const typeDefaults : TypeOptions = {
125
145
delay,
@@ -140,6 +160,18 @@ function _setup(
140
160
return click . call ( userEvent , ...args )
141
161
} ,
142
162
163
+ // copy needs typecasting because of the overloading
164
+ copy : ( ( ...args : Parameters < typeof copy > ) => {
165
+ args [ 0 ] = { ...clipboardDefaults , ...args [ 0 ] }
166
+ return copy . call ( userEvent , ...args )
167
+ } ) as typeof copy ,
168
+
169
+ // cut needs typecasting because of the overloading
170
+ cut : ( ( ...args : Parameters < typeof cut > ) => {
171
+ args [ 0 ] = { ...clipboardDefaults , ...args [ 0 ] }
172
+ return cut . call ( userEvent , ...args )
173
+ } ) as typeof cut ,
174
+
143
175
dblClick : ( ...args : Parameters < typeof dblClick > ) => {
144
176
args [ 1 ] = { ...pointerDefaults , ...clickDefaults , ...args [ 1 ] }
145
177
return dblClick . call ( userEvent , ...args )
0 commit comments