@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.
@@ -1,342 +0,0 @@
1
- import { render, cleanup } from "@testing-library/vue";
2
- import "@testing-library/jest-dom/extend-expect";
3
- import userEvent from "../../src";
4
-
5
- afterEach(cleanup);
6
-
7
- describe("userEvent.click", () => {
8
- it.each(["input", "textarea"])(
9
- "should fire the correct events for <%s>",
10
- (type) => {
11
- const events = [];
12
- const eventsHandler = jest.fn((evt) => events.push(evt.type));
13
- const { getByTestId } = render({
14
- render: function (h) {
15
- return h(type, {
16
- attrs: {
17
- "data-testid": "element",
18
- },
19
- on: {
20
- mouseover: eventsHandler,
21
- mousemove: eventsHandler,
22
- mousedown: eventsHandler,
23
- focus: eventsHandler,
24
- mouseup: eventsHandler,
25
- click: eventsHandler,
26
- },
27
- });
28
- },
29
- });
30
-
31
- userEvent.click(getByTestId("element"));
32
-
33
- // baseElement is always <body>, si wasAnotherElementFocused is false
34
- expect(events).toEqual([
35
- "mouseover",
36
- "mousemove",
37
- "mousedown",
38
- "focus",
39
- "mouseup",
40
- "click",
41
- ]);
42
- }
43
- );
44
-
45
- it('should fire the correct events for <input type="checkbox">', () => {
46
- const events = [];
47
- const eventsHandler = jest.fn((evt) => events.push(evt.type));
48
-
49
- const { getByTestId } = render({
50
- render: function (h) {
51
- return h("input", {
52
- attrs: {
53
- type: "checkbox",
54
- "data-testid": "element",
55
- },
56
- on: {
57
- mouseover: eventsHandler,
58
- mousemove: eventsHandler,
59
- mousedown: eventsHandler,
60
- focus: eventsHandler,
61
- mouseup: eventsHandler,
62
- click: eventsHandler,
63
- change: eventsHandler,
64
- },
65
- });
66
- },
67
- });
68
-
69
- userEvent.click(getByTestId("element"));
70
-
71
- expect(events).toEqual([
72
- "mouseover",
73
- "mousemove",
74
- "mousedown",
75
- "focus",
76
- "mouseup",
77
- "click",
78
- "change",
79
- ]);
80
-
81
- expect(getByTestId("element")).toHaveProperty("checked", true);
82
- });
83
-
84
- it('should fire the correct events for <input type="checkbox" disabled>', () => {
85
- const events = [];
86
- const eventsHandler = jest.fn((evt) => events.push(evt.type));
87
- const { getByTestId } = render({
88
- render: function (h) {
89
- return h("input", {
90
- attrs: {
91
- type: "checkbox",
92
- "data-testid": "element",
93
- disabled: "disabled",
94
- },
95
- on: {
96
- mouseover: eventsHandler,
97
- mousemove: eventsHandler,
98
- mousedown: eventsHandler,
99
- focus: eventsHandler,
100
- mouseup: eventsHandler,
101
- click: eventsHandler,
102
- change: eventsHandler,
103
- },
104
- });
105
- },
106
- });
107
-
108
- userEvent.click(getByTestId("element"));
109
-
110
- expect(events).toEqual([]);
111
-
112
- expect(getByTestId("element")).toHaveProperty("checked", false);
113
- });
114
-
115
- it('should fire the correct events for <input type="radio">', () => {
116
- const events = [];
117
- const eventsHandler = jest.fn((evt) => events.push(evt.type));
118
- const { getByTestId } = render({
119
- render: function (h) {
120
- return h("input", {
121
- attrs: {
122
- type: "radio",
123
- "data-testid": "element",
124
- },
125
- on: {
126
- mouseover: eventsHandler,
127
- mousemove: eventsHandler,
128
- mousedown: eventsHandler,
129
- focus: eventsHandler,
130
- mouseup: eventsHandler,
131
- click: eventsHandler,
132
- change: eventsHandler,
133
- },
134
- });
135
- },
136
- });
137
-
138
- userEvent.click(getByTestId("element"));
139
-
140
- expect(events).toEqual([
141
- "mouseover",
142
- "mousemove",
143
- "mousedown",
144
- "focus",
145
- "mouseup",
146
- "click",
147
- "change",
148
- ]);
149
-
150
- expect(getByTestId("element")).toHaveProperty("checked", true);
151
- });
152
-
153
- it('should fire the correct events for <input type="radio" disabled>', () => {
154
- const events = [];
155
- const eventsHandler = jest.fn((evt) => events.push(evt.type));
156
- const { getByTestId } = render({
157
- render: function (h) {
158
- return h("input", {
159
- attrs: {
160
- type: "radio",
161
- "data-testid": "element",
162
- disabled: "disabled",
163
- },
164
- on: {
165
- mouseover: eventsHandler,
166
- mousemove: eventsHandler,
167
- mousedown: eventsHandler,
168
- focus: eventsHandler,
169
- mouseup: eventsHandler,
170
- click: eventsHandler,
171
- change: eventsHandler,
172
- },
173
- });
174
- },
175
- });
176
-
177
- userEvent.click(getByTestId("element"));
178
-
179
- expect(events).toEqual([]);
180
-
181
- expect(getByTestId("element")).toHaveProperty("checked", false);
182
- });
183
-
184
- it("should fire the correct events for <div>", () => {
185
- const events = [];
186
- const eventsHandler = jest.fn((evt) => events.push(evt.type));
187
- const { getByTestId } = render({
188
- render: function (h) {
189
- return h("div", {
190
- attrs: {
191
- "data-testid": "div",
192
- },
193
- on: {
194
- mouseover: eventsHandler,
195
- mousemove: eventsHandler,
196
- mousedown: eventsHandler,
197
- focus: eventsHandler,
198
- mouseup: eventsHandler,
199
- click: eventsHandler,
200
- },
201
- });
202
- },
203
- });
204
-
205
- userEvent.click(getByTestId("div"));
206
- expect(events).toEqual([
207
- "mouseover",
208
- "mousemove",
209
- "mousedown",
210
- "mouseup",
211
- "click",
212
- ]);
213
- });
214
-
215
- it("toggles the focus", () => {
216
- const { getByTestId } = render({
217
- template: `
218
- <div>
219
- <input data-testid="A" />
220
- <input data-testid="B" />
221
- </div>`,
222
- });
223
-
224
- const a = getByTestId("A");
225
- const b = getByTestId("B");
226
-
227
- expect(a).not.toHaveFocus();
228
- expect(b).not.toHaveFocus();
229
-
230
- userEvent.click(a);
231
- expect(a).toHaveFocus();
232
- expect(b).not.toHaveFocus();
233
-
234
- userEvent.click(b);
235
- expect(a).not.toHaveFocus();
236
- expect(b).toHaveFocus();
237
- });
238
-
239
- it.each(["input", "textarea"])(
240
- "gives focus to <%s> when clicking a <label> with for",
241
- (type) => {
242
- const { getByTestId } = render({
243
- template: `
244
- <div>
245
- <label data-testid="label" for="input" />
246
- <component is="${type}" data-testid="input" id="input" />
247
- </div>`,
248
- });
249
-
250
- userEvent.click(getByTestId("label"));
251
- expect(getByTestId("input")).toHaveFocus();
252
- }
253
- );
254
-
255
- it.each(["input", "textarea"])(
256
- "gives focus to <%s> when clicking a <label> without htmlFor",
257
- (type) => {
258
- const { getByTestId } = render({
259
- template: `
260
- <label data-testid="label">
261
- My label text
262
- <component is="${type}" data-testid="input" />
263
- </label>`,
264
- });
265
-
266
- userEvent.click(getByTestId("label"));
267
- expect(getByTestId("input")).toHaveFocus();
268
- }
269
- );
270
-
271
- it.each(["input", "textarea"])(
272
- "gives focus to <%s> when clicking on an element contained within a <label>",
273
- (type) => {
274
- const { getByText, getByTestId } = render({
275
- template: `
276
- <div>
277
- <label for="input" data-testid="label">Label</Label>
278
- <component is="${type}" id="input" data-testid="input" />
279
- </div>`,
280
- });
281
-
282
- userEvent.click(getByText("Label"));
283
- expect(getByTestId("input")).toHaveFocus();
284
- }
285
- );
286
-
287
- it('checks <input type="checkbox"> when clicking a <label> with htmlFor', () => {
288
- const { getByTestId } = render({
289
- template: `
290
- <div>
291
- <label for="input" data-testid="label">
292
- Label
293
- </label>
294
- <input id="input" data-testid="input" type="checkbox" />
295
- </div>`,
296
- });
297
-
298
- expect(getByTestId("input")).toHaveProperty("checked", false);
299
- userEvent.click(getByTestId("label"));
300
- expect(getByTestId("input")).toHaveProperty("checked", true);
301
- });
302
-
303
- it('checks <input type="checkbox"> when clicking a <label> without htmlFor', () => {
304
- const { getByTestId } = render({
305
- template: `
306
- <div>
307
- <label data-testid="label">
308
- Label
309
- <input id="input" data-testid="input" type="checkbox" />
310
- </label>
311
- </div>`,
312
- });
313
-
314
- expect(getByTestId("input")).toHaveProperty("checked", false);
315
- userEvent.click(getByTestId("label"));
316
- expect(getByTestId("input")).toHaveProperty("checked", true);
317
- });
318
-
319
- it("should submit a form when clicking on a <button>", () => {
320
- const { getByText, emitted } = render({
321
- template: `
322
- <form @submit="$emit('submit')">
323
- <button>Submit</button>
324
- </form>`,
325
- });
326
-
327
- userEvent.click(getByText("Submit"));
328
- expect(emitted().submit).toHaveLength(1);
329
- });
330
-
331
- it('should not submit a form when clicking on a <button type="button">', () => {
332
- const { getByText, emitted } = render({
333
- template: `
334
- <form @submit="$emit('submit')">
335
- <button type="button">Submit</button>
336
- </form>`,
337
- });
338
-
339
- userEvent.click(getByText("Submit"));
340
- expect(emitted()).toEqual({});
341
- });
342
- });
@@ -1,126 +0,0 @@
1
- import { render, cleanup } from "@testing-library/vue";
2
- import "@testing-library/jest-dom/extend-expect";
3
- import userEvent from "../../src";
4
-
5
- afterEach(cleanup);
6
-
7
- describe("userEvent.dblClick", () => {
8
- it.each(["input", "textarea"])(
9
- "should fire the correct events for <%s>",
10
- (type) => {
11
- const events = [];
12
- const eventsHandler = jest.fn((evt) => events.push(evt.type));
13
- const { getByTestId } = render({
14
- render: function (h) {
15
- return h(type, {
16
- attrs: {
17
- "data-testid": "element",
18
- },
19
- on: {
20
- mouseover: eventsHandler,
21
- mousemove: eventsHandler,
22
- mousedown: eventsHandler,
23
- focus: eventsHandler,
24
- mouseup: eventsHandler,
25
- click: eventsHandler,
26
- dblclick: eventsHandler,
27
- },
28
- });
29
- },
30
- });
31
-
32
- userEvent.dblClick(getByTestId("element"));
33
-
34
- expect(events).toEqual([
35
- "mouseover",
36
- "mousemove",
37
- "mousedown",
38
- "focus",
39
- "mouseup",
40
- "click",
41
- "mousedown",
42
- "mouseup",
43
- "click",
44
- "dblclick",
45
- ]);
46
- }
47
- );
48
-
49
- it('should fire the correct events for <input type="checkbox">', () => {
50
- const events = [];
51
- const eventsHandler = jest.fn((evt) => events.push(evt.type));
52
-
53
- const { getByTestId } = render({
54
- render: function (h) {
55
- return h("input", {
56
- attrs: {
57
- type: "checkbox",
58
- "data-testid": "element",
59
- },
60
- on: {
61
- mouseover: eventsHandler,
62
- mousemove: eventsHandler,
63
- mousedown: eventsHandler,
64
- focus: eventsHandler,
65
- mouseup: eventsHandler,
66
- click: eventsHandler,
67
- change: eventsHandler,
68
- },
69
- });
70
- },
71
- });
72
-
73
- userEvent.dblClick(getByTestId("element"));
74
-
75
- expect(events).toEqual([
76
- "mouseover",
77
- "mousemove",
78
- "mousedown",
79
- "focus",
80
- "mouseup",
81
- "click",
82
- "change",
83
- "mousedown",
84
- "mouseup",
85
- "click",
86
- "change",
87
- ]);
88
-
89
- expect(getByTestId("element")).toHaveProperty("checked", false);
90
- });
91
-
92
- it("should fire the correct events for <div>", () => {
93
- const events = [];
94
- const eventsHandler = jest.fn((evt) => events.push(evt.type));
95
- const { getByTestId } = render({
96
- render: function (h) {
97
- return h("div", {
98
- attrs: {
99
- "data-testid": "div",
100
- },
101
- on: {
102
- mouseover: eventsHandler,
103
- mousemove: eventsHandler,
104
- mousedown: eventsHandler,
105
- focus: eventsHandler,
106
- mouseup: eventsHandler,
107
- click: eventsHandler,
108
- change: eventsHandler,
109
- },
110
- });
111
- },
112
- });
113
-
114
- userEvent.dblClick(getByTestId("div"));
115
- expect(events).toEqual([
116
- "mouseover",
117
- "mousemove",
118
- "mousedown",
119
- "mouseup",
120
- "click",
121
- "mousedown",
122
- "mouseup",
123
- "click",
124
- ]);
125
- });
126
- });