Skip to content

Commit b4d264f

Browse files
authored
fix(user-event): Decouple press events from Jest dependency (#1571)
* fix(user-event): Decouple press events from Jest dependency * Add warnAboutRealTimersIfNeeded() tests * Address @mdjastrzebski feedback * refactor: code review changes
1 parent 371534b commit b4d264f

File tree

7 files changed

+81
-112
lines changed

7 files changed

+81
-112
lines changed

src/user-event/event-builder/common.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function touch() {
1616
timestamp: Date.now(),
1717
touches: [],
1818
},
19-
persist: jest.fn(),
20-
currentTarget: { measure: jest.fn() },
19+
persist: () => {},
20+
currentTarget: { measure: () => {} },
2121
target: {},
2222
};
2323
}

src/user-event/press/__tests__/__snapshots__/longPress.test.tsx.snap

+2-31
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,7 @@ exports[`userEvent.longPress with fake timers calls onLongPress if the delayLong
66
"name": "longPress",
77
"payload": {
88
"currentTarget": {
9-
"measure": [MockFunction] {
10-
"calls": [
11-
[
12-
[Function],
13-
],
14-
[
15-
[Function],
16-
],
17-
],
18-
"results": [
19-
{
20-
"type": "return",
21-
"value": undefined,
22-
},
23-
{
24-
"type": "return",
25-
"value": undefined,
26-
},
27-
],
28-
},
9+
"measure": [Function],
2910
},
3011
"dispatchConfig": {
3112
"registrationName": "onResponderGrant",
@@ -41,17 +22,7 @@ exports[`userEvent.longPress with fake timers calls onLongPress if the delayLong
4122
"timestamp": 0,
4223
"touches": [],
4324
},
44-
"persist": [MockFunction] {
45-
"calls": [
46-
[],
47-
],
48-
"results": [
49-
{
50-
"type": "return",
51-
"value": undefined,
52-
},
53-
],
54-
},
25+
"persist": [Function],
5526
"target": {},
5627
},
5728
},

src/user-event/press/__tests__/__snapshots__/press.test.tsx.snap

+6-55
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,7 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu
66
"name": "pressIn",
77
"payload": {
88
"currentTarget": {
9-
"measure": [MockFunction] {
10-
"calls": [
11-
[
12-
[Function],
13-
],
14-
[
15-
[Function],
16-
],
17-
],
18-
"results": [
19-
{
20-
"type": "return",
21-
"value": undefined,
22-
},
23-
{
24-
"type": "return",
25-
"value": undefined,
26-
},
27-
],
28-
},
9+
"measure": [Function],
2910
},
3011
"dispatchConfig": {
3112
"registrationName": "onResponderGrant",
@@ -41,25 +22,15 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu
4122
"timestamp": 0,
4223
"touches": [],
4324
},
44-
"persist": [MockFunction] {
45-
"calls": [
46-
[],
47-
],
48-
"results": [
49-
{
50-
"type": "return",
51-
"value": undefined,
52-
},
53-
],
54-
},
25+
"persist": [Function],
5526
"target": {},
5627
},
5728
},
5829
{
5930
"name": "press",
6031
"payload": {
6132
"currentTarget": {
62-
"measure": [MockFunction],
33+
"measure": [Function],
6334
},
6435
"dispatchConfig": {
6536
"registrationName": "onResponderRelease",
@@ -75,25 +46,15 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu
7546
"timestamp": 0,
7647
"touches": [],
7748
},
78-
"persist": [MockFunction] {
79-
"calls": [
80-
[],
81-
],
82-
"results": [
83-
{
84-
"type": "return",
85-
"value": undefined,
86-
},
87-
],
88-
},
49+
"persist": [Function],
8950
"target": {},
9051
},
9152
},
9253
{
9354
"name": "pressOut",
9455
"payload": {
9556
"currentTarget": {
96-
"measure": [MockFunction],
57+
"measure": [Function],
9758
},
9859
"dispatchConfig": {
9960
"registrationName": "onResponderRelease",
@@ -109,17 +70,7 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu
10970
"timestamp": 0,
11071
"touches": [],
11172
},
112-
"persist": [MockFunction] {
113-
"calls": [
114-
[],
115-
],
116-
"results": [
117-
{
118-
"type": "return",
119-
"value": undefined,
120-
},
121-
],
122-
},
73+
"persist": [Function],
12374
"target": {},
12475
},
12576
},

src/user-event/type/__tests__/__snapshots__/type-managed.test.tsx.snap

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = `
66
"name": "pressIn",
77
"payload": {
88
"currentTarget": {
9-
"measure": [MockFunction],
9+
"measure": [Function],
1010
},
1111
"nativeEvent": {
1212
"changedTouches": [],
@@ -19,7 +19,7 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = `
1919
"timestamp": 100100100100,
2020
"touches": [],
2121
},
22-
"persist": [MockFunction],
22+
"persist": [Function],
2323
"target": {},
2424
},
2525
},
@@ -37,7 +37,7 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = `
3737
"name": "pressOut",
3838
"payload": {
3939
"currentTarget": {
40-
"measure": [MockFunction],
40+
"measure": [Function],
4141
},
4242
"nativeEvent": {
4343
"changedTouches": [],
@@ -50,7 +50,7 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = `
5050
"timestamp": 100100100100,
5151
"touches": [],
5252
},
53-
"persist": [MockFunction],
53+
"persist": [Function],
5454
"target": {},
5555
},
5656
},
@@ -201,7 +201,7 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC"
201201
"name": "pressIn",
202202
"payload": {
203203
"currentTarget": {
204-
"measure": [MockFunction],
204+
"measure": [Function],
205205
},
206206
"nativeEvent": {
207207
"changedTouches": [],
@@ -214,7 +214,7 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC"
214214
"timestamp": 100100100100,
215215
"touches": [],
216216
},
217-
"persist": [MockFunction],
217+
"persist": [Function],
218218
"target": {},
219219
},
220220
},
@@ -232,7 +232,7 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC"
232232
"name": "pressOut",
233233
"payload": {
234234
"currentTarget": {
235-
"measure": [MockFunction],
235+
"measure": [Function],
236236
},
237237
"nativeEvent": {
238238
"changedTouches": [],
@@ -245,7 +245,7 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC"
245245
"timestamp": 100100100100,
246246
"touches": [],
247247
},
248-
"persist": [MockFunction],
248+
"persist": [Function],
249249
"target": {},
250250
},
251251
},

src/user-event/type/__tests__/__snapshots__/type.test.tsx.snap

+16-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1
66
"name": "pressIn",
77
"payload": {
88
"currentTarget": {
9-
"measure": [MockFunction],
9+
"measure": [Function],
1010
},
1111
"nativeEvent": {
1212
"changedTouches": [],
@@ -19,7 +19,7 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1
1919
"timestamp": 100100100100,
2020
"touches": [],
2121
},
22-
"persist": [MockFunction],
22+
"persist": [Function],
2323
"target": {},
2424
},
2525
},
@@ -37,7 +37,7 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1
3737
"name": "pressOut",
3838
"payload": {
3939
"currentTarget": {
40-
"measure": [MockFunction],
40+
"measure": [Function],
4141
},
4242
"nativeEvent": {
4343
"changedTouches": [],
@@ -50,7 +50,7 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1
5050
"timestamp": 100100100100,
5151
"touches": [],
5252
},
53-
"persist": [MockFunction],
53+
"persist": [Function],
5454
"target": {},
5555
},
5656
},
@@ -162,7 +162,7 @@ exports[`type() supports basic case: input: "abc" 1`] = `
162162
"name": "pressIn",
163163
"payload": {
164164
"currentTarget": {
165-
"measure": [MockFunction],
165+
"measure": [Function],
166166
},
167167
"nativeEvent": {
168168
"changedTouches": [],
@@ -175,7 +175,7 @@ exports[`type() supports basic case: input: "abc" 1`] = `
175175
"timestamp": 100100100100,
176176
"touches": [],
177177
},
178-
"persist": [MockFunction],
178+
"persist": [Function],
179179
"target": {},
180180
},
181181
},
@@ -193,7 +193,7 @@ exports[`type() supports basic case: input: "abc" 1`] = `
193193
"name": "pressOut",
194194
"payload": {
195195
"currentTarget": {
196-
"measure": [MockFunction],
196+
"measure": [Function],
197197
},
198198
"nativeEvent": {
199199
"changedTouches": [],
@@ -206,7 +206,7 @@ exports[`type() supports basic case: input: "abc" 1`] = `
206206
"timestamp": 100100100100,
207207
"touches": [],
208208
},
209-
"persist": [MockFunction],
209+
"persist": [Function],
210210
"target": {},
211211
},
212212
},
@@ -357,7 +357,7 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`]
357357
"name": "pressIn",
358358
"payload": {
359359
"currentTarget": {
360-
"measure": [MockFunction],
360+
"measure": [Function],
361361
},
362362
"nativeEvent": {
363363
"changedTouches": [],
@@ -370,7 +370,7 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`]
370370
"timestamp": 100100100100,
371371
"touches": [],
372372
},
373-
"persist": [MockFunction],
373+
"persist": [Function],
374374
"target": {},
375375
},
376376
},
@@ -388,7 +388,7 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`]
388388
"name": "pressOut",
389389
"payload": {
390390
"currentTarget": {
391-
"measure": [MockFunction],
391+
"measure": [Function],
392392
},
393393
"nativeEvent": {
394394
"changedTouches": [],
@@ -401,7 +401,7 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`]
401401
"timestamp": 100100100100,
402402
"touches": [],
403403
},
404-
"persist": [MockFunction],
404+
"persist": [Function],
405405
"target": {},
406406
},
407407
},
@@ -513,7 +513,7 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = `
513513
"name": "pressIn",
514514
"payload": {
515515
"currentTarget": {
516-
"measure": [MockFunction],
516+
"measure": [Function],
517517
},
518518
"nativeEvent": {
519519
"changedTouches": [],
@@ -526,7 +526,7 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = `
526526
"timestamp": 100100100100,
527527
"touches": [],
528528
},
529-
"persist": [MockFunction],
529+
"persist": [Function],
530530
"target": {},
531531
},
532532
},
@@ -544,7 +544,7 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = `
544544
"name": "pressOut",
545545
"payload": {
546546
"currentTarget": {
547-
"measure": [MockFunction],
547+
"measure": [Function],
548548
},
549549
"nativeEvent": {
550550
"changedTouches": [],
@@ -557,7 +557,7 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = `
557557
"timestamp": 100100100100,
558558
"touches": [],
559559
},
560-
"persist": [MockFunction],
560+
"persist": [Function],
561561
"target": {},
562562
},
563563
},

0 commit comments

Comments
 (0)