Skip to content

Commit 56ebf7d

Browse files
committedNov 28, 2021
feat!: remove support for user provided MouseEventInit (#784)
BREAKING CHANGE: `init` parameter has been removed from these APIs: - `userEvent.click` - `userEvent.dblClick` - `userEvent.tripleClick` - `userEvent.hover` - `userEvent.unhover` - `userEvent.selectOptions` - `userEvent.deselectOptions` BREAKING CHANGE: `userEvent.upload` no longer supports `clickInit` as part of its `init` parameter.
1 parent 45dc39a commit 56ebf7d

File tree

11 files changed

+45
-57
lines changed

11 files changed

+45
-57
lines changed
 

‎src/click.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export declare interface clickOptions {
99
export function click(
1010
this: UserEvent,
1111
element: Element,
12-
init?: MouseEventInit,
1312
{
1413
skipHover = false,
1514
skipPointerEventsCheck = false,
@@ -23,41 +22,37 @@ export function click(
2322
// istanbul ignore else
2423
if (!skipHover)
2524
// We just checked for `pointerEvents`. We can always skip this one in `hover`.
26-
this.hover(element, init, {skipPointerEventsCheck: true})
25+
this.hover(element, {skipPointerEventsCheck: true})
2726

28-
const keys =
29-
init?.button === 2 || init?.buttons === 2 ? '[MouseRight]' : '[MouseLeft]'
30-
this.pointer({keys, target: element})
27+
this.pointer({keys: '[MouseLeft]', target: element})
3128
}
3229

3330
export function dblClick(
3431
this: UserEvent,
3532
element: Element,
36-
init?: MouseEventInit,
3733
{skipPointerEventsCheck = false}: clickOptions & PointerOptions = {},
3834
) {
3935
if (!skipPointerEventsCheck && !hasPointerEvents(element)) {
4036
throw new Error(
4137
'unable to double-click element as it has or inherits pointer-events set to "none".',
4238
)
4339
}
44-
this.hover(element, init, {skipPointerEventsCheck})
40+
this.hover(element, {skipPointerEventsCheck: true})
4541

4642
this.pointer({keys: '[MouseLeft][MouseLeft]', target: element})
4743
}
4844

4945
export function tripleClick(
5046
this: UserEvent,
5147
element: Element,
52-
init?: MouseEventInit,
5348
{skipPointerEventsCheck = false}: clickOptions & PointerOptions = {},
5449
) {
5550
if (!skipPointerEventsCheck && !hasPointerEvents(element)) {
5651
throw new Error(
5752
'unable to triple-click element as it has or inherits pointer-events set to "none".',
5853
)
5954
}
60-
this.hover(element, init, {skipPointerEventsCheck: true})
55+
this.hover(element, {skipPointerEventsCheck: true})
6156

6257
this.pointer({keys: '[MouseLeft][MouseLeft][MouseLeft]', target: element})
6358
}

‎src/hover.ts

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {hasPointerEvents, PointerOptions} from './utils'
55
export function hover(
66
this: UserEvent,
77
element: Element,
8-
init?: MouseEventInit,
98
{skipPointerEventsCheck = false}: PointerOptions = {},
109
) {
1110
if (!skipPointerEventsCheck && !hasPointerEvents(element)) {
@@ -23,7 +22,6 @@ export function hover(
2322
export function unhover(
2423
this: UserEvent,
2524
element: Element,
26-
init?: MouseEventInit,
2725
{skipPointerEventsCheck = false}: PointerOptions = {},
2826
) {
2927
if (!skipPointerEventsCheck && !hasPointerEvents(element)) {

‎src/selectOptions.ts

+21-25
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,25 @@ export function selectOptions(
1212
this: UserEvent,
1313
select: Element,
1414
values: HTMLElement | HTMLElement[] | string[] | string,
15-
init?: MouseEventInit,
1615
options: PointerOptions = {},
1716
) {
18-
return selectOptionsBase.call(this, true, select, values, init, options)
17+
return selectOptionsBase.call(this, true, select, values, options)
1918
}
2019

2120
export function deselectOptions(
2221
this: UserEvent,
2322
select: Element,
2423
values: HTMLElement | HTMLElement[] | string[] | string,
25-
init?: MouseEventInit,
2624
options: PointerOptions = {},
2725
) {
28-
return selectOptionsBase.call(this, false, select, values, init, options)
26+
return selectOptionsBase.call(this, false, select, values, options)
2927
}
3028

3129
function selectOptionsBase(
3230
this: UserEvent,
3331
newValue: boolean,
3432
select: Element,
3533
values: HTMLElement | HTMLElement[] | string[] | string,
36-
init: MouseEventInit | undefined,
3734
{skipPointerEventsCheck}: PointerOptions,
3835
) {
3936
if (!newValue && !(select as HTMLSelectElement).multiple) {
@@ -79,27 +76,27 @@ function selectOptionsBase(
7976

8077
// events fired for multiple select are weird. Can't use hover...
8178
if (withPointerEvents) {
82-
fireEvent.pointerOver(option, init)
83-
fireEvent.pointerEnter(select, init)
79+
fireEvent.pointerOver(option)
80+
fireEvent.pointerEnter(select)
8481
fireEvent.mouseOver(option)
8582
fireEvent.mouseEnter(select)
86-
fireEvent.pointerMove(option, init)
87-
fireEvent.mouseMove(option, init)
88-
fireEvent.pointerDown(option, init)
89-
fireEvent.mouseDown(option, init)
83+
fireEvent.pointerMove(option)
84+
fireEvent.mouseMove(option)
85+
fireEvent.pointerDown(option)
86+
fireEvent.mouseDown(option)
9087
}
9188

9289
focus(select)
9390

9491
if (withPointerEvents) {
95-
fireEvent.pointerUp(option, init)
96-
fireEvent.mouseUp(option, init)
92+
fireEvent.pointerUp(option)
93+
fireEvent.mouseUp(option)
9794
}
9895

9996
selectOption(option as HTMLOptionElement)
10097

10198
if (withPointerEvents) {
102-
fireEvent.click(option, init)
99+
fireEvent.click(option)
103100
}
104101
}
105102
} else if (selectedOptions.length === 1) {
@@ -108,7 +105,7 @@ function selectOptionsBase(
108105
: hasPointerEvents(select)
109106
// the click to open the select options
110107
if (withPointerEvents) {
111-
this.click(select, init, {skipPointerEventsCheck: true})
108+
this.click(select, {skipPointerEventsCheck: true})
112109
} else {
113110
focus(select)
114111
}
@@ -118,13 +115,13 @@ function selectOptionsBase(
118115
if (withPointerEvents) {
119116
// the browser triggers another click event on the select for the click on the option
120117
// this second click has no 'down' phase
121-
fireEvent.pointerOver(select, init)
122-
fireEvent.pointerEnter(select, init)
118+
fireEvent.pointerOver(select)
119+
fireEvent.pointerEnter(select)
123120
fireEvent.mouseOver(select)
124121
fireEvent.mouseEnter(select)
125-
fireEvent.pointerUp(select, init)
126-
fireEvent.mouseUp(select, init)
127-
fireEvent.click(select, init)
122+
fireEvent.pointerUp(select)
123+
fireEvent.mouseUp(select)
124+
fireEvent.click(select)
128125
}
129126
} else {
130127
throw getConfig().getElementError(
@@ -134,9 +131,9 @@ function selectOptionsBase(
134131
}
135132
} else if (select.getAttribute('role') === 'listbox') {
136133
selectedOptions.forEach(option => {
137-
this.hover(option, init, {skipPointerEventsCheck})
138-
this.click(option, init, {skipPointerEventsCheck})
139-
this.unhover(option, init, {skipPointerEventsCheck})
134+
this.hover(option, {skipPointerEventsCheck})
135+
this.click(option, {skipPointerEventsCheck})
136+
this.unhover(option, {skipPointerEventsCheck})
140137
})
141138
} else {
142139
throw getConfig().getElementError(
@@ -153,9 +150,8 @@ function selectOptionsBase(
153150
bubbles: true,
154151
cancelable: false,
155152
composed: true,
156-
...init,
157153
}),
158154
)
159-
fireEvent.change(select, init)
155+
fireEvent.change(select)
160156
}
161157
}

‎src/setup.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,22 @@ function _setup(
129129
},
130130

131131
click: (...args: Parameters<typeof click>) => {
132-
args[2] = {...pointerDefaults, ...clickDefaults, ...args[2]}
132+
args[1] = {...pointerDefaults, ...clickDefaults, ...args[1]}
133133
return click.call(userEvent, ...args)
134134
},
135135

136136
dblClick: (...args: Parameters<typeof dblClick>) => {
137-
args[2] = {...pointerDefaults, ...clickDefaults, ...args[2]}
137+
args[1] = {...pointerDefaults, ...clickDefaults, ...args[1]}
138138
return dblClick.call(userEvent, ...args)
139139
},
140140

141141
deselectOptions: (...args: Parameters<typeof deselectOptions>) => {
142-
args[3] = {...pointerDefaults, ...args[3]}
142+
args[2] = {...pointerDefaults, ...args[2]}
143143
return deselectOptions.call(userEvent, ...args)
144144
},
145145

146146
hover: (...args: Parameters<typeof hover>) => {
147-
args[2] = {...pointerDefaults, ...args[2]}
147+
args[1] = {...pointerDefaults, ...args[1]}
148148
return hover.call(userEvent, ...args)
149149
},
150150

@@ -171,7 +171,7 @@ function _setup(
171171
}) as typeof pointer,
172172

173173
selectOptions: (...args: Parameters<typeof selectOptions>) => {
174-
args[3] = {...pointerDefaults, ...args[3]}
174+
args[2] = {...pointerDefaults, ...args[2]}
175175
return selectOptions.call(userEvent, ...args)
176176
},
177177

@@ -205,7 +205,7 @@ function _setup(
205205
}) as typeof type,
206206

207207
unhover: (...args: Parameters<typeof unhover>) => {
208-
args[2] = {...pointerDefaults, ...args[2]}
208+
args[1] = {...pointerDefaults, ...args[1]}
209209
return unhover.call(userEvent, ...args)
210210
},
211211

‎src/upload.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {blur, focus, isDisabled, isElementType} from './utils'
33
import type {UserEvent} from './setup'
44

55
interface uploadInit {
6-
clickInit?: MouseEventInit
76
changeInit?: EventInit
87
}
98

@@ -29,7 +28,7 @@ export function upload(
2928
}
3029
if (isDisabled(element)) return
3130

32-
this.click(element, init?.clickInit)
31+
this.click(element)
3332

3433
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles])
3534
.filter(file => !applyAccept || isAcceptableFile(file, input.accept))

‎tests/click/click.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ test('right click fires `contextmenu` instead of `click', () => {
471471

472472
clearEventCalls()
473473

474-
userEvent.click(element, {buttons: 2})
474+
userEvent.pointer({keys: '[MouseRight]', target: element})
475475
expect(getEvents('contextmenu')).toHaveLength(1)
476476
expect(getEvents('click')).toHaveLength(0)
477477
})
@@ -483,6 +483,6 @@ test('throws when clicking element with pointer-events set to none', () => {
483483

484484
test('does not throws when clicking element with pointer-events set to none and skipPointerEventsCheck is set', () => {
485485
const {element, getEvents} = setup(`<div style="pointer-events: none"></div>`)
486-
userEvent.click(element, undefined, {skipPointerEventsCheck: true})
486+
userEvent.click(element, {skipPointerEventsCheck: true})
487487
expect(getEvents('click')).toHaveLength(1)
488488
})

‎tests/click/dblclick.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,6 @@ test('throws an error when dblClick element with pointer-events set to none', ()
290290

291291
test('does not throws when clicking element with pointer-events set to none and skipPointerEventsCheck is set', () => {
292292
const {element, getEvents} = setup(`<div style="pointer-events: none"></div>`)
293-
userEvent.dblClick(element, undefined, {skipPointerEventsCheck: true})
293+
userEvent.dblClick(element, {skipPointerEventsCheck: true})
294294
expect(getEvents('click')).toHaveLength(2)
295295
})

‎tests/hover/hover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ test('does not throws when hover element with pointer-events set to none and ski
135135
const {element, getEventSnapshot} = setup(
136136
`<div style="pointer-events: none"></div>`,
137137
)
138-
userEvent.hover(element, undefined, {skipPointerEventsCheck: true})
138+
userEvent.hover(element, {skipPointerEventsCheck: true})
139139
expect(getEventSnapshot()).toMatchInlineSnapshot(`
140140
Events fired on: div
141141

‎tests/hover/unhover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test('does not throws when hover element with pointer-events set to none and ski
5555
const {element, getEventSnapshot} = setup(
5656
`<div style="pointer-events: none"></div>`,
5757
)
58-
userEvent.unhover(element, undefined, {skipPointerEventsCheck: true})
58+
userEvent.unhover(element, {skipPointerEventsCheck: true})
5959
expect(getEventSnapshot()).toMatchInlineSnapshot(`
6060
Events fired on: div
6161

‎tests/selectOptions/select.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ test('fires correct events when pointer events set to none but skipPointerEvents
263263
const {select, options, getEventSnapshot} = setupSelect({
264264
pointerEvents: 'none',
265265
})
266-
userEvent.selectOptions(select, '2', undefined, {
266+
userEvent.selectOptions(select, '2', {
267267
skipPointerEventsCheck: true,
268268
})
269269
expect(getEventSnapshot()).toMatchInlineSnapshot(`
@@ -303,7 +303,7 @@ test('fires correct events on multi-selects when pointer events is set and skipP
303303
multiple: true,
304304
pointerEvents: 'none',
305305
})
306-
userEvent.selectOptions(select, ['1', '3'], undefined, {
306+
userEvent.selectOptions(select, ['1', '3'], {
307307
skipPointerEventsCheck: true,
308308
})
309309
expect(getEventSnapshot()).toMatchInlineSnapshot(`

‎tests/setup.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -165,31 +165,31 @@ cases<APICase>(
165165
click: {
166166
api: 'click',
167167
elementArg: 0,
168-
optionsArg: 2,
168+
optionsArg: 1,
169169
options: {
170170
skipPointerEventsCheck: true,
171171
},
172172
},
173173
dblClick: {
174174
api: 'dblClick',
175175
elementArg: 0,
176-
optionsArg: 2,
176+
optionsArg: 1,
177177
options: {
178178
skipPointerEventsCheck: true,
179179
},
180180
},
181181
hover: {
182182
api: 'hover',
183183
elementArg: 0,
184-
optionsArg: 2,
184+
optionsArg: 1,
185185
options: {
186186
skipPointerEventsCheck: true,
187187
},
188188
},
189189
unhover: {
190190
api: 'unhover',
191191
elementArg: 0,
192-
optionsArg: 2,
192+
optionsArg: 1,
193193
options: {
194194
skipPointerEventsCheck: true,
195195
},
@@ -221,7 +221,7 @@ cases<APICase>(
221221
api: 'selectOptions',
222222
args: [null, ['foo']],
223223
elementArg: 0,
224-
optionsArg: 3,
224+
optionsArg: 2,
225225
options: {
226226
skipPointerEventsCheck: true,
227227
},
@@ -230,7 +230,7 @@ cases<APICase>(
230230
api: 'deselectOptions',
231231
args: [null, ['foo']],
232232
elementArg: 0,
233-
optionsArg: 3,
233+
optionsArg: 2,
234234
options: {
235235
skipPointerEventsCheck: true,
236236
},

0 commit comments

Comments
 (0)
Please sign in to comment.