@react-aria/test-utils 1.0.0-alpha.2 → 1.0.0-alpha.4

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.
Files changed (71) hide show
  1. package/LICENSE +201 -0
  2. package/dist/combobox.main.js +116 -82
  3. package/dist/combobox.main.js.map +1 -1
  4. package/dist/combobox.mjs +117 -83
  5. package/dist/combobox.module.js +117 -83
  6. package/dist/combobox.module.js.map +1 -1
  7. package/dist/events.main.js.map +1 -1
  8. package/dist/events.module.js.map +1 -1
  9. package/dist/gridlist.main.js +102 -59
  10. package/dist/gridlist.main.js.map +1 -1
  11. package/dist/gridlist.mjs +103 -60
  12. package/dist/gridlist.module.js +103 -60
  13. package/dist/gridlist.module.js.map +1 -1
  14. package/dist/listbox.main.js +135 -0
  15. package/dist/listbox.main.js.map +1 -0
  16. package/dist/listbox.mjs +130 -0
  17. package/dist/listbox.module.js +130 -0
  18. package/dist/listbox.module.js.map +1 -0
  19. package/dist/main.js.map +1 -1
  20. package/dist/menu.main.js +197 -119
  21. package/dist/menu.main.js.map +1 -1
  22. package/dist/menu.mjs +198 -120
  23. package/dist/menu.module.js +198 -120
  24. package/dist/menu.module.js.map +1 -1
  25. package/dist/module.js.map +1 -1
  26. package/dist/select.main.js +116 -70
  27. package/dist/select.main.js.map +1 -1
  28. package/dist/select.mjs +117 -71
  29. package/dist/select.module.js +117 -71
  30. package/dist/select.module.js.map +1 -1
  31. package/dist/table.main.js +170 -143
  32. package/dist/table.main.js.map +1 -1
  33. package/dist/table.mjs +171 -144
  34. package/dist/table.module.js +171 -144
  35. package/dist/table.module.js.map +1 -1
  36. package/dist/tabs.main.js +133 -0
  37. package/dist/tabs.main.js.map +1 -0
  38. package/dist/tabs.mjs +128 -0
  39. package/dist/tabs.module.js +128 -0
  40. package/dist/tabs.module.js.map +1 -0
  41. package/dist/testSetup.main.js +2 -6
  42. package/dist/testSetup.main.js.map +1 -1
  43. package/dist/testSetup.mjs +2 -6
  44. package/dist/testSetup.module.js +2 -6
  45. package/dist/testSetup.module.js.map +1 -1
  46. package/dist/tree.main.js +165 -0
  47. package/dist/tree.main.js.map +1 -0
  48. package/dist/tree.mjs +160 -0
  49. package/dist/tree.module.js +160 -0
  50. package/dist/tree.module.js.map +1 -0
  51. package/dist/types.d.ts +607 -139
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/user.main.js +16 -5
  54. package/dist/user.main.js.map +1 -1
  55. package/dist/user.mjs +16 -5
  56. package/dist/user.module.js +16 -5
  57. package/dist/user.module.js.map +1 -1
  58. package/package.json +5 -5
  59. package/src/combobox.ts +105 -36
  60. package/src/events.ts +1 -1
  61. package/src/gridlist.ts +146 -59
  62. package/src/index.ts +1 -1
  63. package/src/listbox.ts +226 -0
  64. package/src/menu.ts +207 -55
  65. package/src/select.ts +137 -44
  66. package/src/table.ts +134 -78
  67. package/src/tabs.ts +198 -0
  68. package/src/testSetup.ts +2 -6
  69. package/src/tree.ts +248 -0
  70. package/src/types.ts +133 -0
  71. package/src/user.ts +62 -37
package/src/table.ts CHANGED
@@ -11,23 +11,29 @@
11
11
  */
12
12
 
13
13
  import {act, fireEvent, waitFor, within} from '@testing-library/react';
14
- import {BaseTesterOpts, UserOpts} from './user';
14
+ import {GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';
15
15
  import {pressElement, triggerLongPress} from './events';
16
- export interface TableOptions extends UserOpts, BaseTesterOpts {
17
- user: any,
18
- advanceTimer: UserOpts['advanceTimer']
16
+
17
+ interface TableToggleRowOpts extends ToggleGridRowOpts {}
18
+ interface TableToggleSortOpts {
19
+ /**
20
+ * The index, text, or node of the column to toggle selection for.
21
+ */
22
+ column: number | string | HTMLElement,
23
+ /**
24
+ * What interaction type to use when sorting the column. Defaults to the interaction type set on the tester.
25
+ */
26
+ interactionType?: UserOpts['interactionType']
19
27
  }
28
+ interface TableRowActionOpts extends GridRowActionOpts {}
20
29
 
21
- // TODO: Previously used logic like https://github.com/testing-library/react-testing-library/blame/c63b873072d62c858959c2a19e68f8e2cc0b11be/src/pure.js#L16
22
- // but https://github.com/testing-library/dom-testing-library/issues/987#issuecomment-891901804 indicates that it may falsely indicate that fake timers are enabled
23
- // when they aren't
24
30
  export class TableTester {
25
31
  private user;
26
32
  private _interactionType: UserOpts['interactionType'];
27
33
  private _advanceTimer: UserOpts['advanceTimer'];
28
34
  private _table: HTMLElement;
29
35
 
30
- constructor(opts: TableOptions) {
36
+ constructor(opts: TableTesterOpts) {
31
37
  let {root, user, interactionType, advanceTimer} = opts;
32
38
  this.user = user;
33
39
  this._interactionType = interactionType || 'mouse';
@@ -35,21 +41,43 @@ export class TableTester {
35
41
  this._table = root;
36
42
  }
37
43
 
38
- setInteractionType = (type: UserOpts['interactionType']) => {
44
+ /**
45
+ * Set the interaction type used by the table tester.
46
+ */
47
+ setInteractionType(type: UserOpts['interactionType']) {
39
48
  this._interactionType = type;
40
- };
49
+ }
41
50
 
42
- toggleRowSelection = async (opts: {index?: number, text?: string, needsLongPress?: boolean, interactionType?: UserOpts['interactionType']} = {}) => {
51
+ /**
52
+ * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.
53
+ */
54
+ async toggleRowSelection(opts: TableToggleRowOpts) {
43
55
  let {
44
- index,
45
- text,
56
+ row,
46
57
  needsLongPress,
58
+ checkboxSelection = true,
47
59
  interactionType = this._interactionType
48
60
  } = opts;
49
61
 
50
- let row = this.findRow({index, text});
62
+ if (typeof row === 'string' || typeof row === 'number') {
63
+ row = this.findRow({rowIndexOrText: row});
64
+ }
65
+
66
+ if (!row) {
67
+ throw new Error('Target row not found in the table.');
68
+ }
69
+
51
70
  let rowCheckbox = within(row).queryByRole('checkbox');
52
- if (rowCheckbox) {
71
+
72
+ if (interactionType === 'keyboard' && !checkboxSelection) {
73
+ // TODO: for now focus the row directly until I add keyboard navigation
74
+ await act(async () => {
75
+ row.focus();
76
+ });
77
+ await this.user.keyboard('{Space}');
78
+ return;
79
+ }
80
+ if (rowCheckbox && checkboxSelection) {
53
81
  await pressElement(this.user, rowCheckbox, interactionType);
54
82
  } else {
55
83
  let cell = within(row).getAllByRole('gridcell')[0];
@@ -68,32 +96,27 @@ export class TableTester {
68
96
  await pressElement(this.user, cell, interactionType);
69
97
  }
70
98
  }
71
-
72
- // Handle cases where the table may transition in response to the row selection/deselection
73
- await act(async () => {
74
- if (this._advanceTimer == null) {
75
- throw new Error('No advanceTimers provided for table transition.');
76
- }
77
-
78
- await this._advanceTimer(200);
79
- });
80
99
  };
81
100
 
82
- toggleSort = async (opts: {index?: number, text?: string, interactionType?: UserOpts['interactionType']} = {}) => {
101
+ /**
102
+ * Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.
103
+ */
104
+ async toggleSort(opts: TableToggleSortOpts) {
83
105
  let {
84
- index,
85
- text,
106
+ column,
86
107
  interactionType = this._interactionType
87
108
  } = opts;
88
109
 
89
110
  let columnheader;
90
- if (index != null) {
91
- columnheader = this.columns[index];
92
- } else if (text != null) {
93
- columnheader = within(this.rowGroups[0]).getByText(text);
111
+ if (typeof column === 'number') {
112
+ columnheader = this.columns[column];
113
+ } else if (typeof column === 'string') {
114
+ columnheader = within(this.rowGroups[0]).getByText(column);
94
115
  while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {
95
116
  columnheader = columnheader.parentElement;
96
117
  }
118
+ } else {
119
+ columnheader = column;
97
120
  }
98
121
 
99
122
  let menuButton = within(columnheader).queryByRole('button');
@@ -145,12 +168,12 @@ export class TableTester {
145
168
  }
146
169
 
147
170
  // Handle cases where the table may transition in response to the row selection/deselection
148
- await act(async () => {
149
- if (this._advanceTimer == null) {
150
- throw new Error('No advanceTimers provided for table transition.');
151
- }
171
+ if (!this._advanceTimer) {
172
+ throw new Error('No advanceTimers provided for table transition.');
173
+ }
152
174
 
153
- await this._advanceTimer(200);
175
+ await act(async () => {
176
+ await this._advanceTimer?.(200);
154
177
  });
155
178
 
156
179
  await waitFor(() => {
@@ -163,38 +186,46 @@ export class TableTester {
163
186
  } else {
164
187
  await pressElement(this.user, columnheader, interactionType);
165
188
  }
166
- };
167
- // TODO: should there be a util for triggering a row action? Perhaps there should be but it would rely on the user teling us the config of the
168
- // table. Maybe we could rely on the user knowing to trigger a press/double click? We could have the user pass in "needsDoubleClick"
169
- // It is also iffy if there is any row selected because then the table is in selectionMode and the below actions will simply toggle row selection
170
- triggerRowAction = async (opts: {index?: number, text?: string, needsDoubleClick?: boolean, interactionType?: UserOpts['interactionType']} = {}) => {
189
+ }
190
+
191
+ /**
192
+ * Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.
193
+ */
194
+ async triggerRowAction(opts: TableRowActionOpts) {
171
195
  let {
172
- index,
173
- text,
196
+ row,
174
197
  needsDoubleClick,
175
198
  interactionType = this._interactionType
176
199
  } = opts;
177
200
 
178
- let row = this.findRow({index, text});
179
- if (row) {
180
- if (needsDoubleClick) {
181
- await this.user.dblClick(row);
182
- } else if (interactionType === 'keyboard') {
183
- act(() => row.focus());
184
- await this.user.keyboard('[Enter]');
185
- } else {
186
- await pressElement(this.user, row, interactionType);
187
- }
201
+ if (typeof row === 'string' || typeof row === 'number') {
202
+ row = this.findRow({rowIndexOrText: row});
203
+ }
204
+
205
+ if (!row) {
206
+ throw new Error('Target row not found in the table.');
188
207
  }
189
- };
208
+
209
+ if (needsDoubleClick) {
210
+ await this.user.dblClick(row);
211
+ } else if (interactionType === 'keyboard') {
212
+ // TODO: add keyboard navigation instead of focusing the row directly. Will need to consider if the focus in in the columns
213
+ act(() => row.focus());
214
+ await this.user.keyboard('[Enter]');
215
+ } else {
216
+ await pressElement(this.user, row, interactionType);
217
+ }
218
+ }
190
219
 
191
220
  // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.
192
221
  // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend
193
222
  // on the mocks the user sets up for their row height/etc.
194
223
  // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really
195
224
  // add much value if we provide that to them
196
-
197
- toggleSelectAll = async (opts: {interactionType?: UserOpts['interactionType']} = {}) => {
225
+ /**
226
+ * Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.
227
+ */
228
+ async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}) {
198
229
  let {
199
230
  interactionType = this._interactionType
200
231
  } = opts;
@@ -205,30 +236,35 @@ export class TableTester {
205
236
  } else {
206
237
  await pressElement(this.user, checkbox, interactionType);
207
238
  }
208
- };
239
+ }
209
240
 
210
- findRow = (opts: {index?: number, text?: string} = {}) => {
241
+ /**
242
+ * Returns a row matching the specified index or text content.
243
+ */
244
+ findRow(opts: {rowIndexOrText: number | string}): HTMLElement {
211
245
  let {
212
- index,
213
- text
246
+ rowIndexOrText
214
247
  } = opts;
215
248
 
216
249
  let row;
217
250
  let rows = this.rows;
218
251
  let bodyRowGroup = this.rowGroups[1];
219
- if (index != null) {
220
- row = rows[index];
221
- } else if (text != null) {
222
- row = within(bodyRowGroup).getByText(text);
252
+ if (typeof rowIndexOrText === 'number') {
253
+ row = rows[rowIndexOrText];
254
+ } else if (typeof rowIndexOrText === 'string') {
255
+ row = within(bodyRowGroup).getByText(rowIndexOrText);
223
256
  while (row && row.getAttribute('role') !== 'row') {
224
257
  row = row.parentElement;
225
258
  }
226
259
  }
227
260
 
228
261
  return row;
229
- };
262
+ }
230
263
 
231
- findCell = (opts: {text: string}) => {
264
+ /**
265
+ * Returns a cell matching the specified text content.
266
+ */
267
+ findCell(opts: {text: string}) {
232
268
  let {
233
269
  text
234
270
  } = opts;
@@ -245,38 +281,58 @@ export class TableTester {
245
281
  }
246
282
 
247
283
  return cell;
248
- };
284
+ }
249
285
 
250
- get table() {
286
+ /**
287
+ * Returns the table.
288
+ */
289
+ get table(): HTMLElement {
251
290
  return this._table;
252
291
  }
253
292
 
254
- get rowGroups() {
293
+ /**
294
+ * Returns the row groups within the table.
295
+ */
296
+ get rowGroups(): HTMLElement[] {
255
297
  let table = this._table;
256
298
  return table ? within(table).queryAllByRole('rowgroup') : [];
257
299
  }
258
300
 
259
- get columns() {
301
+ /**
302
+ * Returns the columns within the table.
303
+ */
304
+ get columns(): HTMLElement[] {
260
305
  let headerRowGroup = this.rowGroups[0];
261
306
  return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];
262
307
  }
263
308
 
264
- get rows() {
309
+ /**
310
+ * Returns the rows within the table if any.
311
+ */
312
+ get rows(): HTMLElement[] {
265
313
  let bodyRowGroup = this.rowGroups[1];
266
314
  return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];
267
315
  }
268
316
 
269
- get selectedRows() {
317
+ /**
318
+ * Returns the currently selected rows within the table if any.
319
+ */
320
+ get selectedRows(): HTMLElement[] {
270
321
  return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');
271
322
  }
272
323
 
273
- get rowHeaders() {
274
- let table = this.table;
275
- return table ? within(table).queryAllByRole('rowheader') : [];
324
+ /**
325
+ * Returns the row headers within the table if any.
326
+ */
327
+ get rowHeaders(): HTMLElement[] {
328
+ return within(this.table).queryAllByRole('rowheader');
276
329
  }
277
330
 
278
- get cells() {
279
- let table = this.table;
280
- return table ? within(table).queryAllByRole('gridcell') : [];
331
+ /**
332
+ * Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.
333
+ */
334
+ cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {
335
+ let {element = this.table} = opts;
336
+ return within(element).queryAllByRole('gridcell');
281
337
  }
282
338
  }
package/src/tabs.ts ADDED
@@ -0,0 +1,198 @@
1
+ /*
2
+ * Copyright 2024 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {act, within} from '@testing-library/react';
14
+ import {Direction, Orientation, TabsTesterOpts, UserOpts} from './types';
15
+ import {pressElement} from './events';
16
+
17
+ interface TriggerTabOptions {
18
+ /**
19
+ * What interaction type to use when triggering a tab. Defaults to the interaction type set on the tester.
20
+ */
21
+ interactionType?: UserOpts['interactionType'],
22
+ /**
23
+ * The index, text, or node of the tab to toggle selection for.
24
+ */
25
+ tab: number | string | HTMLElement,
26
+ /**
27
+ * Whether the tab needs to be activated manually rather than on focus.
28
+ */
29
+ manualActivation?: boolean
30
+ }
31
+
32
+ export class TabsTester {
33
+ private user;
34
+ private _interactionType: UserOpts['interactionType'];
35
+ private _tablist: HTMLElement;
36
+ private _direction: Direction;
37
+
38
+ constructor(opts: TabsTesterOpts) {
39
+ let {root, user, interactionType, direction} = opts;
40
+ this.user = user;
41
+ this._interactionType = interactionType || 'mouse';
42
+ this._direction = direction || 'ltr';
43
+
44
+ this._tablist = root;
45
+ let tablist = within(root).queryAllByRole('tablist');
46
+ if (tablist.length > 0) {
47
+ this._tablist = tablist[0];
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Set the interaction type used by the tabs tester.
53
+ */
54
+ setInteractionType(type: UserOpts['interactionType']) {
55
+ this._interactionType = type;
56
+ }
57
+
58
+ // TODO: This is pretty similar across most the utils, refactor to make it generic?
59
+ /**
60
+ * Returns a tab matching the specified index or text content.
61
+ */
62
+ findTab(opts: {tabIndexOrText: number | string}): HTMLElement {
63
+ let {
64
+ tabIndexOrText
65
+ } = opts;
66
+
67
+ let tab;
68
+ let tabs = this.tabs;
69
+ if (typeof tabIndexOrText === 'number') {
70
+ tab = tabs[tabIndexOrText];
71
+ } else if (typeof tabIndexOrText === 'string') {
72
+ tab = (within(this._tablist).getByText(tabIndexOrText).closest('[role=tab]'))! as HTMLElement;
73
+ }
74
+
75
+ return tab;
76
+ }
77
+
78
+ // TODO: also quite similar across more utils albeit with orientation, refactor to make generic
79
+ private async keyboardNavigateToTab(opts: {tab: HTMLElement, orientation?: Orientation}) {
80
+ let {tab, orientation = 'vertical'} = opts;
81
+ let tabs = this.tabs;
82
+ let targetIndex = tabs.indexOf(tab);
83
+ if (targetIndex === -1) {
84
+ throw new Error('Tab provided is not in the tablist');
85
+ }
86
+
87
+ if (!this._tablist.contains(document.activeElement)) {
88
+ let selectedTab = this.selectedTab;
89
+ if (selectedTab != null) {
90
+ act(() => selectedTab.focus());
91
+ } else {
92
+ act(() => tabs.find(tab => !(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'))?.focus());
93
+ }
94
+ }
95
+
96
+ let currIndex = this.tabs.indexOf(document.activeElement as HTMLElement);
97
+ if (currIndex === -1) {
98
+ throw new Error('ActiveElement is not in the tablist');
99
+ }
100
+
101
+ let arrowUp = 'ArrowUp';
102
+ let arrowDown = 'ArrowDown';
103
+ if (orientation === 'horizontal') {
104
+ if (this._direction === 'ltr') {
105
+ arrowUp = 'ArrowLeft';
106
+ arrowDown = 'ArrowRight';
107
+ } else {
108
+ arrowUp = 'ArrowRight';
109
+ arrowDown = 'ArrowLeft';
110
+ }
111
+ }
112
+
113
+ let movementDirection = targetIndex > currIndex ? 'down' : 'up';
114
+ for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {
115
+ await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);
116
+ }
117
+ };
118
+
119
+ /**
120
+ * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.
121
+ */
122
+ async triggerTab(opts: TriggerTabOptions) {
123
+ let {
124
+ tab,
125
+ interactionType = this._interactionType,
126
+ manualActivation
127
+ } = opts;
128
+
129
+ if (typeof tab === 'string' || typeof tab === 'number') {
130
+ tab = this.findTab({tabIndexOrText: tab});
131
+ }
132
+
133
+ if (!tab) {
134
+ throw new Error('Target tab not found in the tablist.');
135
+ } else if (tab.hasAttribute('disabled')) {
136
+ throw new Error('Target tab is disabled.');
137
+ }
138
+
139
+ if (interactionType === 'keyboard') {
140
+ if (document.activeElement !== this._tablist || !this._tablist.contains(document.activeElement)) {
141
+ act(() => this._tablist.focus());
142
+ }
143
+
144
+ let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';
145
+ await this.keyboardNavigateToTab({tab, orientation: tabsOrientation as Orientation});
146
+ if (manualActivation) {
147
+ await this.user.keyboard('[Enter]');
148
+ }
149
+ } else {
150
+ await pressElement(this.user, tab, interactionType);
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Returns the tablist.
156
+ */
157
+ get tablist(): HTMLElement {
158
+ return this._tablist;
159
+ }
160
+
161
+ /**
162
+ * Returns the tabpanels.
163
+ */
164
+ get tabpanels(): HTMLElement[] {
165
+ let tabpanels = [] as HTMLElement[];
166
+ for (let tab of this.tabs) {
167
+ let controlId = tab.getAttribute('aria-controls');
168
+ let panel = controlId != null ? document.getElementById(controlId) : null;
169
+ if (panel != null) {
170
+ tabpanels.push(panel);
171
+ }
172
+ }
173
+
174
+ return tabpanels;
175
+ }
176
+
177
+ /**
178
+ * Returns the tabs in the tablist.
179
+ */
180
+ get tabs(): HTMLElement[] {
181
+ return within(this.tablist).queryAllByRole('tab');
182
+ }
183
+
184
+ /**
185
+ * Returns the currently selected tab in the tablist if any.
186
+ */
187
+ get selectedTab(): HTMLElement | null {
188
+ return this.tabs.find(tab => tab.getAttribute('aria-selected') === 'true') || null;
189
+ }
190
+
191
+ /**
192
+ * Returns the currently active tabpanel if any.
193
+ */
194
+ get activeTabpanel(): HTMLElement | null {
195
+ let activeTabpanelId = this.selectedTab?.getAttribute('aria-controls');
196
+ return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;
197
+ }
198
+ }
package/src/testSetup.ts CHANGED
@@ -14,9 +14,8 @@
14
14
  * Enables reading pageX/pageY from fireEvent.mouse*(..., {pageX: ..., pageY: ...}).
15
15
  */
16
16
  export function installMouseEvent() {
17
+ let oldMouseEvent = MouseEvent;
17
18
  beforeAll(() => {
18
- let oldMouseEvent = MouseEvent;
19
- // @ts-ignore
20
19
  global.MouseEvent = class FakeMouseEvent extends MouseEvent {
21
20
  _init: {pageX: number, pageY: number};
22
21
  constructor(name, init) {
@@ -30,12 +29,9 @@ export function installMouseEvent() {
30
29
  return this._init.pageY;
31
30
  }
32
31
  };
33
- // @ts-ignore
34
- global.MouseEvent.oldMouseEvent = oldMouseEvent;
35
32
  });
36
33
  afterAll(() => {
37
- // @ts-ignore
38
- global.MouseEvent = global.MouseEvent.oldMouseEvent;
34
+ global.MouseEvent = oldMouseEvent;
39
35
  });
40
36
  }
41
37