@testing-library/user-event 10.3.2 → 10.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/LICENSE +2 -3
- package/README.md +201 -107
- package/dist/index.js +326 -252
- package/package.json +42 -43
- package/typings/index.d.ts +24 -20
- package/.all-contributorsrc +0 -311
- package/.babelrc +0 -13
- package/.gitattributes +0 -1
- package/.nvmrc +0 -1
- package/.prettierrc.js +0 -3
- package/.travis.yml +0 -30
- package/__tests__/react/clear.js +0 -94
- package/__tests__/react/click.js +0 -437
- package/__tests__/react/dblclick.js +0 -211
- package/__tests__/react/selectoptions.js +0 -282
- package/__tests__/react/tab.js +0 -277
- package/__tests__/react/type.js +0 -265
- package/__tests__/react/upload.js +0 -124
- package/__tests__/vue/click.js +0 -342
- package/__tests__/vue/dblclick.js +0 -126
- package/__tests__/vue/selectoptions.js +0 -254
- package/__tests__/vue/type.js +0 -240
- package/lint-staged.config.js +0 -21
- package/other/dog.png +0 -0
- package/src/index.js +0 -373
package/__tests__/react/click.js
DELETED
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { render, cleanup } from "@testing-library/react";
|
|
3
|
-
import "@testing-library/jest-dom/extend-expect";
|
|
4
|
-
import userEvent from "../../src";
|
|
5
|
-
|
|
6
|
-
afterEach(cleanup);
|
|
7
|
-
|
|
8
|
-
describe("userEvent.click", () => {
|
|
9
|
-
it.each(["input", "textarea"])(
|
|
10
|
-
"should fire the correct events for <%s>",
|
|
11
|
-
(type) => {
|
|
12
|
-
const events = [];
|
|
13
|
-
const eventsHandler = jest.fn((evt) => events.push(evt.type));
|
|
14
|
-
const { getByTestId } = render(
|
|
15
|
-
React.createElement(type, {
|
|
16
|
-
"data-testid": "element",
|
|
17
|
-
onMouseOver: eventsHandler,
|
|
18
|
-
onMouseMove: eventsHandler,
|
|
19
|
-
onMouseDown: eventsHandler,
|
|
20
|
-
onFocus: eventsHandler,
|
|
21
|
-
onMouseUp: eventsHandler,
|
|
22
|
-
onClick: eventsHandler,
|
|
23
|
-
})
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
userEvent.click(getByTestId("element"));
|
|
27
|
-
|
|
28
|
-
expect(events).toEqual([
|
|
29
|
-
"mouseover",
|
|
30
|
-
"mousemove",
|
|
31
|
-
"mousedown",
|
|
32
|
-
"focus",
|
|
33
|
-
"mouseup",
|
|
34
|
-
"click",
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
it('should fire the correct events for <input type="checkbox">', () => {
|
|
40
|
-
const events = [];
|
|
41
|
-
const eventsHandler = jest.fn((evt) => events.push(evt.type));
|
|
42
|
-
const { getByTestId } = render(
|
|
43
|
-
<input
|
|
44
|
-
data-testid="element"
|
|
45
|
-
type="checkbox"
|
|
46
|
-
onMouseOver={eventsHandler}
|
|
47
|
-
onMouseMove={eventsHandler}
|
|
48
|
-
onMouseDown={eventsHandler}
|
|
49
|
-
onFocus={eventsHandler}
|
|
50
|
-
onMouseUp={eventsHandler}
|
|
51
|
-
onClick={eventsHandler}
|
|
52
|
-
onChange={eventsHandler}
|
|
53
|
-
/>
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
userEvent.click(getByTestId("element"));
|
|
57
|
-
|
|
58
|
-
expect(events).toEqual([
|
|
59
|
-
"mouseover",
|
|
60
|
-
"mousemove",
|
|
61
|
-
"mousedown",
|
|
62
|
-
"focus",
|
|
63
|
-
"mouseup",
|
|
64
|
-
"click",
|
|
65
|
-
"change",
|
|
66
|
-
]);
|
|
67
|
-
|
|
68
|
-
expect(getByTestId("element")).toHaveProperty("checked", true);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should fire the correct events for <input type="checkbox" disabled>', () => {
|
|
72
|
-
const events = [];
|
|
73
|
-
const eventsHandler = jest.fn((evt) => events.push(evt.type));
|
|
74
|
-
const { getByTestId } = render(
|
|
75
|
-
<input
|
|
76
|
-
data-testid="element"
|
|
77
|
-
type="checkbox"
|
|
78
|
-
onMouseOver={eventsHandler}
|
|
79
|
-
onMouseMove={eventsHandler}
|
|
80
|
-
onMouseDown={eventsHandler}
|
|
81
|
-
onFocus={eventsHandler}
|
|
82
|
-
onMouseUp={eventsHandler}
|
|
83
|
-
onClick={eventsHandler}
|
|
84
|
-
onChange={eventsHandler}
|
|
85
|
-
disabled
|
|
86
|
-
/>
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
userEvent.click(getByTestId("element"));
|
|
90
|
-
|
|
91
|
-
expect(events).toEqual([]);
|
|
92
|
-
|
|
93
|
-
expect(getByTestId("element")).toHaveProperty("checked", false);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should fire the correct events for <input type="radio">', () => {
|
|
97
|
-
const events = [];
|
|
98
|
-
const eventsHandler = jest.fn((evt) => events.push(evt.type));
|
|
99
|
-
const { getByTestId } = render(
|
|
100
|
-
<input
|
|
101
|
-
data-testid="element"
|
|
102
|
-
type="radio"
|
|
103
|
-
onMouseOver={eventsHandler}
|
|
104
|
-
onMouseMove={eventsHandler}
|
|
105
|
-
onMouseDown={eventsHandler}
|
|
106
|
-
onFocus={eventsHandler}
|
|
107
|
-
onMouseUp={eventsHandler}
|
|
108
|
-
onClick={eventsHandler}
|
|
109
|
-
onChange={eventsHandler}
|
|
110
|
-
/>
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
userEvent.click(getByTestId("element"));
|
|
114
|
-
|
|
115
|
-
expect(events).toEqual([
|
|
116
|
-
"mouseover",
|
|
117
|
-
"mousemove",
|
|
118
|
-
"mousedown",
|
|
119
|
-
"focus",
|
|
120
|
-
"mouseup",
|
|
121
|
-
"click",
|
|
122
|
-
"change",
|
|
123
|
-
]);
|
|
124
|
-
|
|
125
|
-
expect(getByTestId("element")).toHaveProperty("checked", true);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should fire the correct events for <input type="radio" disabled>', () => {
|
|
129
|
-
const events = [];
|
|
130
|
-
const eventsHandler = jest.fn((evt) => events.push(evt.type));
|
|
131
|
-
const { getByTestId } = render(
|
|
132
|
-
<input
|
|
133
|
-
data-testid="element"
|
|
134
|
-
type="radio"
|
|
135
|
-
onMouseOver={eventsHandler}
|
|
136
|
-
onMouseMove={eventsHandler}
|
|
137
|
-
onMouseDown={eventsHandler}
|
|
138
|
-
onFocus={eventsHandler}
|
|
139
|
-
onMouseUp={eventsHandler}
|
|
140
|
-
onClick={eventsHandler}
|
|
141
|
-
onChange={eventsHandler}
|
|
142
|
-
disabled
|
|
143
|
-
/>
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
userEvent.click(getByTestId("element"));
|
|
147
|
-
|
|
148
|
-
expect(events).toEqual([]);
|
|
149
|
-
|
|
150
|
-
expect(getByTestId("element")).toHaveProperty("checked", false);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("should fire the correct events for <div>", () => {
|
|
154
|
-
const events = [];
|
|
155
|
-
const eventsHandler = jest.fn((evt) => events.push(evt.type));
|
|
156
|
-
const { getByTestId } = render(
|
|
157
|
-
<div
|
|
158
|
-
data-testid="div"
|
|
159
|
-
onMouseOver={eventsHandler}
|
|
160
|
-
onMouseMove={eventsHandler}
|
|
161
|
-
onMouseDown={eventsHandler}
|
|
162
|
-
onFocus={eventsHandler}
|
|
163
|
-
onMouseUp={eventsHandler}
|
|
164
|
-
onClick={eventsHandler}
|
|
165
|
-
/>
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
userEvent.click(getByTestId("div"));
|
|
169
|
-
expect(events).toEqual([
|
|
170
|
-
"mouseover",
|
|
171
|
-
"mousemove",
|
|
172
|
-
"mousedown",
|
|
173
|
-
"mouseup",
|
|
174
|
-
"click",
|
|
175
|
-
]);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("toggles the focus", () => {
|
|
179
|
-
const { getByTestId } = render(
|
|
180
|
-
<React.Fragment>
|
|
181
|
-
<input data-testid="A" />
|
|
182
|
-
<input data-testid="B" />
|
|
183
|
-
</React.Fragment>
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
const a = getByTestId("A");
|
|
187
|
-
const b = getByTestId("B");
|
|
188
|
-
|
|
189
|
-
expect(a).not.toHaveFocus();
|
|
190
|
-
expect(b).not.toHaveFocus();
|
|
191
|
-
|
|
192
|
-
userEvent.click(a);
|
|
193
|
-
expect(a).toHaveFocus();
|
|
194
|
-
expect(b).not.toHaveFocus();
|
|
195
|
-
|
|
196
|
-
userEvent.click(b);
|
|
197
|
-
expect(a).not.toHaveFocus();
|
|
198
|
-
expect(b).toHaveFocus();
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("should not blur when mousedown prevents default", () => {
|
|
202
|
-
let events = [];
|
|
203
|
-
const eventsHandler = jest.fn((evt) => events.push(evt.type));
|
|
204
|
-
const commonEvents = {
|
|
205
|
-
onBlur: eventsHandler,
|
|
206
|
-
onMouseOver: eventsHandler,
|
|
207
|
-
onMouseMove: eventsHandler,
|
|
208
|
-
onMouseDown: eventsHandler,
|
|
209
|
-
onFocus: eventsHandler,
|
|
210
|
-
onMouseUp: eventsHandler,
|
|
211
|
-
onClick: eventsHandler,
|
|
212
|
-
onChange: eventsHandler,
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
const { getByTestId } = render(
|
|
216
|
-
<React.Fragment>
|
|
217
|
-
<input data-testid="A" {...commonEvents} />
|
|
218
|
-
<input
|
|
219
|
-
data-testid="B"
|
|
220
|
-
{...commonEvents}
|
|
221
|
-
onMouseDown={(e) => {
|
|
222
|
-
e.preventDefault();
|
|
223
|
-
eventsHandler(e);
|
|
224
|
-
}}
|
|
225
|
-
/>
|
|
226
|
-
<input data-testid="C" {...commonEvents} />
|
|
227
|
-
</React.Fragment>
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
const a = getByTestId("A");
|
|
231
|
-
const b = getByTestId("B");
|
|
232
|
-
const c = getByTestId("C");
|
|
233
|
-
|
|
234
|
-
expect(a).not.toHaveFocus();
|
|
235
|
-
expect(b).not.toHaveFocus();
|
|
236
|
-
expect(c).not.toHaveFocus();
|
|
237
|
-
|
|
238
|
-
userEvent.click(a);
|
|
239
|
-
expect(a).toHaveFocus();
|
|
240
|
-
expect(b).not.toHaveFocus();
|
|
241
|
-
expect(c).not.toHaveFocus();
|
|
242
|
-
|
|
243
|
-
expect(events).toEqual([
|
|
244
|
-
"mouseover",
|
|
245
|
-
"mousemove",
|
|
246
|
-
"mousedown",
|
|
247
|
-
"focus",
|
|
248
|
-
"mouseup",
|
|
249
|
-
"click",
|
|
250
|
-
]);
|
|
251
|
-
|
|
252
|
-
events = [];
|
|
253
|
-
|
|
254
|
-
userEvent.click(b);
|
|
255
|
-
expect(a).toHaveFocus();
|
|
256
|
-
expect(b).not.toHaveFocus();
|
|
257
|
-
expect(c).not.toHaveFocus();
|
|
258
|
-
|
|
259
|
-
expect(events).toEqual([
|
|
260
|
-
"mousemove",
|
|
261
|
-
"mouseover",
|
|
262
|
-
"mousemove",
|
|
263
|
-
"mousedown",
|
|
264
|
-
"mouseup",
|
|
265
|
-
"click",
|
|
266
|
-
]);
|
|
267
|
-
|
|
268
|
-
events = [];
|
|
269
|
-
|
|
270
|
-
userEvent.click(c);
|
|
271
|
-
expect(a).not.toHaveFocus();
|
|
272
|
-
expect(b).not.toHaveFocus();
|
|
273
|
-
expect(c).toHaveFocus();
|
|
274
|
-
|
|
275
|
-
expect(events).toEqual([
|
|
276
|
-
"mousemove",
|
|
277
|
-
"mouseover",
|
|
278
|
-
"mousemove",
|
|
279
|
-
"mousedown",
|
|
280
|
-
"blur",
|
|
281
|
-
"focus",
|
|
282
|
-
"mouseup",
|
|
283
|
-
"click",
|
|
284
|
-
]);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it("does not lose focus when click updates focus", () => {
|
|
288
|
-
const FocusComponent = () => {
|
|
289
|
-
const inputRef = React.useRef();
|
|
290
|
-
const focusInput = () => inputRef.current.focus();
|
|
291
|
-
|
|
292
|
-
return (
|
|
293
|
-
<React.Fragment>
|
|
294
|
-
<input data-testid="input" ref={inputRef} />
|
|
295
|
-
<button onClick={focusInput}>Update Focus</button>
|
|
296
|
-
</React.Fragment>
|
|
297
|
-
);
|
|
298
|
-
};
|
|
299
|
-
const { getByTestId, getByText } = render(<FocusComponent />);
|
|
300
|
-
|
|
301
|
-
const input = getByTestId("input");
|
|
302
|
-
const button = getByText("Update Focus");
|
|
303
|
-
|
|
304
|
-
expect(input).not.toHaveFocus();
|
|
305
|
-
|
|
306
|
-
userEvent.click(button);
|
|
307
|
-
expect(input).toHaveFocus();
|
|
308
|
-
|
|
309
|
-
userEvent.click(button);
|
|
310
|
-
expect(input).toHaveFocus();
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it.each(["input", "textarea"])(
|
|
314
|
-
"gives focus to <%s> when clicking a <label> with htmlFor",
|
|
315
|
-
(type) => {
|
|
316
|
-
const { getByTestId } = render(
|
|
317
|
-
<React.Fragment>
|
|
318
|
-
<label htmlFor="input" data-testid="label">
|
|
319
|
-
Label
|
|
320
|
-
</label>
|
|
321
|
-
{React.createElement(type, { id: "input", "data-testid": "input" })}
|
|
322
|
-
</React.Fragment>
|
|
323
|
-
);
|
|
324
|
-
userEvent.click(getByTestId("label"));
|
|
325
|
-
expect(getByTestId("input")).toHaveFocus();
|
|
326
|
-
}
|
|
327
|
-
);
|
|
328
|
-
|
|
329
|
-
it.each(["input", "textarea"])(
|
|
330
|
-
"gives focus to <%s> when clicking a <label> without htmlFor",
|
|
331
|
-
(type) => {
|
|
332
|
-
const { getByTestId } = render(
|
|
333
|
-
<React.Fragment>
|
|
334
|
-
<label data-testid="label">
|
|
335
|
-
Label
|
|
336
|
-
{React.createElement(type, { "data-testid": "input" })}
|
|
337
|
-
</label>
|
|
338
|
-
</React.Fragment>
|
|
339
|
-
);
|
|
340
|
-
userEvent.click(getByTestId("label"));
|
|
341
|
-
expect(getByTestId("input")).toHaveFocus();
|
|
342
|
-
}
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
it.each(["input", "textarea"])(
|
|
346
|
-
"gives focus to <%s> when clicking on an element contained within a <label>",
|
|
347
|
-
(type) => {
|
|
348
|
-
const { getByText, getByTestId } = render(
|
|
349
|
-
<React.Fragment>
|
|
350
|
-
<label htmlFor="input" data-testid="label">
|
|
351
|
-
<span>Label</span>
|
|
352
|
-
</label>
|
|
353
|
-
{React.createElement(type, { id: "input", "data-testid": "input" })}
|
|
354
|
-
</React.Fragment>
|
|
355
|
-
);
|
|
356
|
-
userEvent.click(getByText("Label"));
|
|
357
|
-
expect(getByTestId("input")).toHaveFocus();
|
|
358
|
-
}
|
|
359
|
-
);
|
|
360
|
-
|
|
361
|
-
it('checks <input type="checkbox"> when clicking a <label> with htmlFor', () => {
|
|
362
|
-
const { getByTestId } = render(
|
|
363
|
-
<React.Fragment>
|
|
364
|
-
<label htmlFor="input" data-testid="label">
|
|
365
|
-
Label
|
|
366
|
-
</label>
|
|
367
|
-
<input id="input" data-testid="input" type="checkbox" />
|
|
368
|
-
</React.Fragment>
|
|
369
|
-
);
|
|
370
|
-
expect(getByTestId("input")).toHaveProperty("checked", false);
|
|
371
|
-
userEvent.click(getByTestId("label"));
|
|
372
|
-
expect(getByTestId("input")).toHaveProperty("checked", true);
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
it('checks <input type="checkbox"> when clicking a <label> without htmlFor', () => {
|
|
376
|
-
const { getByTestId } = render(
|
|
377
|
-
<React.Fragment>
|
|
378
|
-
<label data-testid="label">
|
|
379
|
-
Label
|
|
380
|
-
<input id="input" data-testid="input" type="checkbox" />
|
|
381
|
-
</label>
|
|
382
|
-
</React.Fragment>
|
|
383
|
-
);
|
|
384
|
-
expect(getByTestId("input")).toHaveProperty("checked", false);
|
|
385
|
-
userEvent.click(getByTestId("label"));
|
|
386
|
-
expect(getByTestId("input")).toHaveProperty("checked", true);
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
it("should submit a form when clicking on a <button>", () => {
|
|
390
|
-
const onSubmit = jest.fn();
|
|
391
|
-
const { getByText } = render(
|
|
392
|
-
<form onSubmit={onSubmit}>
|
|
393
|
-
<button>Submit</button>
|
|
394
|
-
</form>
|
|
395
|
-
);
|
|
396
|
-
userEvent.click(getByText("Submit"));
|
|
397
|
-
expect(onSubmit).toHaveBeenCalledTimes(1);
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
it('should not submit a form when clicking on a <button type="button">', () => {
|
|
401
|
-
const onSubmit = jest.fn();
|
|
402
|
-
const { getByText } = render(
|
|
403
|
-
<form onSubmit={onSubmit}>
|
|
404
|
-
<button type="button">Submit</button>
|
|
405
|
-
</form>
|
|
406
|
-
);
|
|
407
|
-
userEvent.click(getByText("Submit"));
|
|
408
|
-
expect(onSubmit).not.toHaveBeenCalled();
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
it("should not fire blur on current element if is the same as previous", () => {
|
|
412
|
-
const onBlur = jest.fn();
|
|
413
|
-
const { getByText } = render(<button onBlur={onBlur}>Blur</button>);
|
|
414
|
-
userEvent.click(getByText("Blur"));
|
|
415
|
-
expect(onBlur).not.toHaveBeenCalled();
|
|
416
|
-
userEvent.click(getByText("Blur"));
|
|
417
|
-
expect(onBlur).not.toHaveBeenCalled();
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
it.each(["input", "textarea"])(
|
|
421
|
-
"should not give focus for <%s> when mouseDown is prevented",
|
|
422
|
-
(type) => {
|
|
423
|
-
const { getByTestId } = render(
|
|
424
|
-
React.createElement(type, {
|
|
425
|
-
"data-testid": "element",
|
|
426
|
-
onMouseDown: (evt) => {
|
|
427
|
-
evt.preventDefault();
|
|
428
|
-
},
|
|
429
|
-
})
|
|
430
|
-
);
|
|
431
|
-
|
|
432
|
-
userEvent.click(getByTestId("element"));
|
|
433
|
-
|
|
434
|
-
expect(getByTestId("element")).not.toHaveFocus();
|
|
435
|
-
}
|
|
436
|
-
);
|
|
437
|
-
});
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { render, cleanup } from "@testing-library/react";
|
|
3
|
-
import "@testing-library/jest-dom/extend-expect";
|
|
4
|
-
import userEvent from "../../src";
|
|
5
|
-
|
|
6
|
-
afterEach(cleanup);
|
|
7
|
-
|
|
8
|
-
describe("userEvent.dblClick", () => {
|
|
9
|
-
it.each(["input", "textarea"])(
|
|
10
|
-
"should fire the correct events for <%s>",
|
|
11
|
-
(type) => {
|
|
12
|
-
const events = [];
|
|
13
|
-
const eventsHandler = jest.fn((evt) => events.push(evt.type));
|
|
14
|
-
const { getByTestId } = render(
|
|
15
|
-
React.createElement(type, {
|
|
16
|
-
"data-testid": "element",
|
|
17
|
-
onMouseOver: eventsHandler,
|
|
18
|
-
onMouseMove: eventsHandler,
|
|
19
|
-
onMouseDown: eventsHandler,
|
|
20
|
-
onFocus: eventsHandler,
|
|
21
|
-
onMouseUp: eventsHandler,
|
|
22
|
-
onClick: eventsHandler,
|
|
23
|
-
onDoubleClick: eventsHandler,
|
|
24
|
-
})
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
userEvent.dblClick(getByTestId("element"));
|
|
28
|
-
|
|
29
|
-
expect(events).toEqual([
|
|
30
|
-
"mouseover",
|
|
31
|
-
"mousemove",
|
|
32
|
-
"mousedown",
|
|
33
|
-
"focus",
|
|
34
|
-
"mouseup",
|
|
35
|
-
"click",
|
|
36
|
-
"mousedown",
|
|
37
|
-
"mouseup",
|
|
38
|
-
"click",
|
|
39
|
-
"dblclick",
|
|
40
|
-
]);
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
it('should fire the correct events for <input type="checkbox">', () => {
|
|
45
|
-
const events = [];
|
|
46
|
-
const eventsHandler = jest.fn((evt) => events.push(evt.type));
|
|
47
|
-
const { getByTestId } = render(
|
|
48
|
-
<input
|
|
49
|
-
data-testid="element"
|
|
50
|
-
type="checkbox"
|
|
51
|
-
onMouseOver={eventsHandler}
|
|
52
|
-
onMouseMove={eventsHandler}
|
|
53
|
-
onMouseDown={eventsHandler}
|
|
54
|
-
onFocus={eventsHandler}
|
|
55
|
-
onMouseUp={eventsHandler}
|
|
56
|
-
onClick={eventsHandler}
|
|
57
|
-
onChange={eventsHandler}
|
|
58
|
-
/>
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
userEvent.dblClick(getByTestId("element"));
|
|
62
|
-
|
|
63
|
-
expect(events).toEqual([
|
|
64
|
-
"mouseover",
|
|
65
|
-
"mousemove",
|
|
66
|
-
"mousedown",
|
|
67
|
-
"focus",
|
|
68
|
-
"mouseup",
|
|
69
|
-
"click",
|
|
70
|
-
"change",
|
|
71
|
-
"mousedown",
|
|
72
|
-
"mouseup",
|
|
73
|
-
"click",
|
|
74
|
-
"change",
|
|
75
|
-
]);
|
|
76
|
-
|
|
77
|
-
expect(getByTestId("element")).toHaveProperty("checked", false);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("should fire the correct events for <div>", () => {
|
|
81
|
-
const events = [];
|
|
82
|
-
const eventsHandler = jest.fn((evt) => events.push(evt.type));
|
|
83
|
-
const { getByTestId } = render(
|
|
84
|
-
<div
|
|
85
|
-
data-testid="div"
|
|
86
|
-
onMouseOver={eventsHandler}
|
|
87
|
-
onMouseMove={eventsHandler}
|
|
88
|
-
onMouseDown={eventsHandler}
|
|
89
|
-
onFocus={eventsHandler}
|
|
90
|
-
onMouseUp={eventsHandler}
|
|
91
|
-
onClick={eventsHandler}
|
|
92
|
-
/>
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
userEvent.dblClick(getByTestId("div"));
|
|
96
|
-
expect(events).toEqual([
|
|
97
|
-
"mouseover",
|
|
98
|
-
"mousemove",
|
|
99
|
-
"mousedown",
|
|
100
|
-
"mouseup",
|
|
101
|
-
"click",
|
|
102
|
-
"mousedown",
|
|
103
|
-
"mouseup",
|
|
104
|
-
"click",
|
|
105
|
-
]);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("should not fire blur on current element if is the same as previous", () => {
|
|
109
|
-
const onBlur = jest.fn();
|
|
110
|
-
const { getByText } = render(<button onBlur={onBlur}>Blur</button>);
|
|
111
|
-
userEvent.dblClick(getByText("Blur"));
|
|
112
|
-
expect(onBlur).not.toHaveBeenCalled();
|
|
113
|
-
userEvent.dblClick(getByText("Blur"));
|
|
114
|
-
expect(onBlur).not.toHaveBeenCalled();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("should not blur when mousedown prevents default", () => {
|
|
118
|
-
let events = [];
|
|
119
|
-
const eventsHandler = jest.fn((evt) => events.push(evt.type));
|
|
120
|
-
const commonEvents = {
|
|
121
|
-
onBlur: eventsHandler,
|
|
122
|
-
onMouseOver: eventsHandler,
|
|
123
|
-
onMouseMove: eventsHandler,
|
|
124
|
-
onMouseDown: eventsHandler,
|
|
125
|
-
onFocus: eventsHandler,
|
|
126
|
-
onMouseUp: eventsHandler,
|
|
127
|
-
onClick: eventsHandler,
|
|
128
|
-
onChange: eventsHandler,
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const { getByTestId } = render(
|
|
132
|
-
<React.Fragment>
|
|
133
|
-
<input data-testid="A" {...commonEvents} />
|
|
134
|
-
<input
|
|
135
|
-
data-testid="B"
|
|
136
|
-
{...commonEvents}
|
|
137
|
-
onMouseDown={(e) => {
|
|
138
|
-
e.preventDefault();
|
|
139
|
-
eventsHandler(e);
|
|
140
|
-
}}
|
|
141
|
-
/>
|
|
142
|
-
<input data-testid="C" {...commonEvents} />
|
|
143
|
-
</React.Fragment>
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
const a = getByTestId("A");
|
|
147
|
-
const b = getByTestId("B");
|
|
148
|
-
const c = getByTestId("C");
|
|
149
|
-
|
|
150
|
-
expect(a).not.toHaveFocus();
|
|
151
|
-
expect(b).not.toHaveFocus();
|
|
152
|
-
expect(c).not.toHaveFocus();
|
|
153
|
-
|
|
154
|
-
userEvent.dblClick(a);
|
|
155
|
-
expect(a).toHaveFocus();
|
|
156
|
-
expect(b).not.toHaveFocus();
|
|
157
|
-
expect(c).not.toHaveFocus();
|
|
158
|
-
|
|
159
|
-
expect(events).toEqual([
|
|
160
|
-
"mouseover",
|
|
161
|
-
"mousemove",
|
|
162
|
-
"mousedown",
|
|
163
|
-
"focus",
|
|
164
|
-
"mouseup",
|
|
165
|
-
"click",
|
|
166
|
-
"mousedown",
|
|
167
|
-
"mouseup",
|
|
168
|
-
"click",
|
|
169
|
-
]);
|
|
170
|
-
|
|
171
|
-
events = [];
|
|
172
|
-
|
|
173
|
-
userEvent.dblClick(b);
|
|
174
|
-
expect(a).toHaveFocus();
|
|
175
|
-
expect(b).not.toHaveFocus();
|
|
176
|
-
expect(c).not.toHaveFocus();
|
|
177
|
-
|
|
178
|
-
expect(events).toEqual([
|
|
179
|
-
"mousemove",
|
|
180
|
-
"mouseover",
|
|
181
|
-
"mousemove",
|
|
182
|
-
"mousedown",
|
|
183
|
-
"mouseup",
|
|
184
|
-
"click",
|
|
185
|
-
"mousedown",
|
|
186
|
-
"mouseup",
|
|
187
|
-
"click",
|
|
188
|
-
]);
|
|
189
|
-
|
|
190
|
-
events = [];
|
|
191
|
-
|
|
192
|
-
userEvent.dblClick(c);
|
|
193
|
-
expect(a).not.toHaveFocus();
|
|
194
|
-
expect(b).not.toHaveFocus();
|
|
195
|
-
expect(c).toHaveFocus();
|
|
196
|
-
|
|
197
|
-
expect(events).toEqual([
|
|
198
|
-
"mousemove",
|
|
199
|
-
"mouseover",
|
|
200
|
-
"mousemove",
|
|
201
|
-
"mousedown",
|
|
202
|
-
"blur",
|
|
203
|
-
"focus",
|
|
204
|
-
"mouseup",
|
|
205
|
-
"click",
|
|
206
|
-
"mousedown",
|
|
207
|
-
"mouseup",
|
|
208
|
-
"click",
|
|
209
|
-
]);
|
|
210
|
-
});
|
|
211
|
-
});
|