Skip to content

Commit 4955eb2

Browse files
authored
chore: no shadow support for test utils right now (#9581)
* feat: revert shadow dom contains for test-utils * update eslint config to ignore test-utils * run yarn install
1 parent ac7aabe commit 4955eb2

14 files changed

Lines changed: 37 additions & 41 deletions

File tree

eslint.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,15 @@ export default [{
501501
message: "Use getOwnerDocument from @react-aria/utils instead.",
502502
}],
503503
},
504+
}, {
505+
files: [
506+
"packages/@react-aria/test-utils/src/**/*.ts",
507+
"packages/@react-aria/test-utils/src/**/*.tsx",
508+
],
509+
510+
rules: {
511+
"rsp-rules/no-non-shadow-contains": OFF,
512+
},
504513
}, {
505514
files: ["packages/@react-spectrum/s2/**", "packages/dev/s2-docs/**"],
506515

packages/@react-aria/test-utils/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"url": "https://github.com/adobe/react-spectrum"
2727
},
2828
"dependencies": {
29-
"@react-aria/utils": "^3.32.0",
3029
"@swc/helpers": "^0.5.0"
3130
},
3231
"peerDependencies": {

packages/@react-aria/test-utils/src/checkboxgroup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import {act, within} from '@testing-library/react';
1414
import {CheckboxGroupTesterOpts, UserOpts} from './types';
15-
import {nodeContains} from '@react-aria/utils';
1615
import {pressElement} from './events';
1716

1817
interface TriggerCheckboxOptions {
@@ -95,7 +94,7 @@ export class CheckboxGroupTester {
9594
throw new Error('Checkbox provided is not in the checkbox group.');
9695
}
9796

98-
if (!nodeContains(this.checkboxgroup, document.activeElement)) {
97+
if (!this.checkboxgroup.contains(document.activeElement)) {
9998
act(() => checkboxes[0].focus());
10099
}
101100

packages/@react-aria/test-utils/src/combobox.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import {act, waitFor, within} from '@testing-library/react';
1414
import {ComboBoxTesterOpts, UserOpts} from './types';
15-
import {nodeContains} from '@react-aria/utils';
1615

1716
interface ComboBoxOpenOpts {
1817
/**
@@ -177,7 +176,7 @@ export class ComboBoxTester {
177176

178177
if (option.getAttribute('href') == null) {
179178
await waitFor(() => {
180-
if (nodeContains(document, listbox)) {
179+
if (document.contains(listbox)) {
181180
throw new Error('Expected listbox element to not be in the document after selecting an option');
182181
} else {
183182
return true;
@@ -199,7 +198,7 @@ export class ComboBoxTester {
199198
await this.user.keyboard('[Escape]');
200199

201200
await waitFor(() => {
202-
if (nodeContains(document, listbox)) {
201+
if (document.contains(listbox)) {
203202
throw new Error('Expected listbox element to not be in the document after selecting an option');
204203
} else {
205204
return true;

packages/@react-aria/test-utils/src/dialog.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import {act, waitFor, within} from '@testing-library/react';
1414
import {DialogTesterOpts, UserOpts} from './types';
15-
import {nodeContains} from '@react-aria/utils';
1615

1716
interface DialogOpenOpts {
1817
/**
@@ -97,7 +96,7 @@ export class DialogTester {
9796
}
9897
});
9998

100-
if (dialog && document.activeElement !== this._trigger && nodeContains(dialog, document.activeElement)) {
99+
if (dialog && document.activeElement !== this._trigger && dialog.contains(document.activeElement)) {
101100
this._dialog = dialog;
102101
} else {
103102
throw new Error('New modal dialog doesnt contain the active element OR the active element is still the trigger. Uncertain if the proper modal dialog was found');
@@ -114,7 +113,7 @@ export class DialogTester {
114113
if (dialog) {
115114
await this.user.keyboard('[Escape]');
116115
await waitFor(() => {
117-
if (nodeContains(document, dialog)) {
116+
if (document.contains(dialog)) {
118117
throw new Error('Expected the dialog to not be in the document after closing it.');
119118
} else {
120119
this._dialog = undefined;
@@ -139,6 +138,6 @@ export class DialogTester {
139138
* Returns the dialog if present.
140139
*/
141140
get dialog(): HTMLElement | null {
142-
return this._dialog && nodeContains(document, this._dialog) ? this._dialog : null;
141+
return this._dialog && document.contains(this._dialog) ? this._dialog : null;
143142
}
144143
}

packages/@react-aria/test-utils/src/gridlist.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import {act, within} from '@testing-library/react';
1414
import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';
1515
import {GridListTesterOpts, GridRowActionOpts, ToggleGridRowOpts, UserOpts} from './types';
16-
import {nodeContains} from '@react-aria/utils';
1716

1817
interface GridListToggleRowOpts extends ToggleGridRowOpts {}
1918
interface GridListRowActionOpts extends GridRowActionOpts {}
@@ -67,13 +66,13 @@ export class GridListTester {
6766
throw new Error('Option provided is not in the gridlist');
6867
}
6968

70-
if (document.activeElement !== this._gridlist && !nodeContains(this._gridlist, document.activeElement)) {
69+
if (document.activeElement !== this._gridlist && !this._gridlist.contains(document.activeElement)) {
7170
act(() => this._gridlist.focus());
7271
}
7372

7473
if (document.activeElement === this._gridlist) {
7574
await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
76-
} else if (nodeContains(this._gridlist, document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {
75+
} else if (this._gridlist.contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {
7776
do {
7877
await this.user.keyboard('[ArrowLeft]');
7978
} while (document.activeElement!.getAttribute('role') !== 'row');

packages/@react-aria/test-utils/src/listbox.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import {act, within} from '@testing-library/react';
1414
import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';
1515
import {ListBoxTesterOpts, UserOpts} from './types';
16-
import {nodeContains} from '@react-aria/utils';
1716

1817
interface ListBoxToggleOptionOpts {
1918
/**
@@ -104,7 +103,7 @@ export class ListBoxTester {
104103
throw new Error('Option provided is not in the listbox');
105104
}
106105

107-
if (document.activeElement !== this._listbox && !nodeContains(this._listbox, document.activeElement)) {
106+
if (document.activeElement !== this._listbox && !this._listbox.contains(document.activeElement)) {
108107
act(() => this._listbox.focus());
109108
await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
110109
}

packages/@react-aria/test-utils/src/menu.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import {act, waitFor, within} from '@testing-library/react';
1414
import {MenuTesterOpts, UserOpts} from './types';
15-
import {nodeContains} from '@react-aria/utils';
1615
import {triggerLongPress} from './events';
1716

1817
interface MenuOpenOpts {
@@ -216,7 +215,7 @@ export class MenuTester {
216215
return;
217216
}
218217

219-
if (document.activeElement !== menu && !nodeContains(menu, document.activeElement)) {
218+
if (document.activeElement !== menu && !menu.contains(document.activeElement)) {
220219
act(() => menu.focus());
221220
}
222221

@@ -263,7 +262,7 @@ export class MenuTester {
263262
// close. In React 16, focus actually makes it all the way to the root menu's submenu trigger so we need check the root menu
264263
if (this._isSubmenu) {
265264
await waitFor(() => {
266-
if (document.activeElement === this.trigger || nodeContains(this._rootMenu, document.activeElement)) {
265+
if (document.activeElement === this.trigger || this._rootMenu?.contains(document.activeElement)) {
267266
throw new Error('Expected focus after selecting an submenu option to move away from the original submenu trigger.');
268267
} else {
269268
return true;
@@ -343,7 +342,7 @@ export class MenuTester {
343342
private async keyboardNavigateToOption(opts: {option: HTMLElement}) {
344343
let {option} = opts;
345344
let options = this.options();
346-
let targetIndex = options.findIndex(opt => (opt === option) || nodeContains(opt, option));
345+
let targetIndex = options.findIndex(opt => (opt === option) || opt.contains(option));
347346

348347
if (targetIndex === -1) {
349348
throw new Error('Option provided is not in the menu');
@@ -379,7 +378,7 @@ export class MenuTester {
379378
}
380379
});
381380

382-
if (nodeContains(document, menu)) {
381+
if (document.contains(menu)) {
383382
throw new Error('Expected the menu to not be in the document after closing it.');
384383
}
385384
}

packages/@react-aria/test-utils/src/radiogroup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import {act, within} from '@testing-library/react';
1414
import {Direction, Orientation, RadioGroupTesterOpts, UserOpts} from './types';
15-
import {nodeContains} from '@react-aria/utils';
1615
import {pressElement} from './events';
1716

1817
interface TriggerRadioOptions {
@@ -95,7 +94,7 @@ export class RadioGroupTester {
9594
throw new Error('Radio provided is not in the radio group.');
9695
}
9796

98-
if (!nodeContains(this.radiogroup, document.activeElement)) {
97+
if (!this.radiogroup.contains(document.activeElement)) {
9998
let selectedRadio = this.selectedRadio;
10099
if (selectedRadio != null) {
101100
act(() => selectedRadio.focus());

packages/@react-aria/test-utils/src/select.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*/
1212

1313
import {act, waitFor, within} from '@testing-library/react';
14-
import {nodeContains} from '@react-aria/utils';
1514
import {SelectTesterOpts, UserOpts} from './types';
1615

1716
interface SelectOpenOpts {
@@ -111,7 +110,7 @@ export class SelectTester {
111110
}
112111
});
113112

114-
if (listbox && nodeContains(document, listbox)) {
113+
if (listbox && document.contains(listbox)) {
115114
throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');
116115
}
117116
}
@@ -192,7 +191,7 @@ export class SelectTester {
192191
return;
193192
}
194193

195-
if (document.activeElement !== listbox && !nodeContains(listbox, document.activeElement)) {
194+
if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) {
196195
act(() => listbox.focus());
197196
}
198197
await this.keyboardNavigateToOption({option});
@@ -215,7 +214,7 @@ export class SelectTester {
215214
}
216215
});
217216

218-
if (nodeContains(document, listbox)) {
217+
if (document.contains(listbox)) {
219218
throw new Error('Expected select element listbox to not be in the document after selecting an option');
220219
}
221220
}

0 commit comments

Comments
 (0)