Skip to content

Commit 4b48a50

Browse files
authored
fix: make aria test utils helpers work with vitest-browser-react (adobe#9756)
* fix: make aria test utils helpers work with vitest-browser-react * fix lint and try to fix react 16/17 * keep old peer dep for now, remove when bumping to full release
1 parent 1ebb0fe commit 4b48a50

File tree

16 files changed

+51
-12
lines changed

16 files changed

+51
-12
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@swc/helpers": "^0.5.0"
3030
},
3131
"peerDependencies": {
32+
"@testing-library/dom": "^10.1.0",
3233
"@testing-library/react": "^16.0.0",
3334
"@testing-library/user-event": "^14.0.0",
3435
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2025 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 * as React from 'react';
14+
import * as ReactDOMTestUtils from 'react-dom/test-utils';
15+
16+
let actImpl: typeof ReactDOMTestUtils.act;
17+
if (typeof React.act === 'function') {
18+
actImpl = React.act;
19+
} else {
20+
actImpl = ReactDOMTestUtils.act;
21+
}
22+
23+
export const act = actImpl;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {act, within} from '@testing-library/react';
13+
import {act} from './act';
1414
import {CheckboxGroupTesterOpts, UserOpts} from './types';
1515
import {pressElement} from './events';
16+
import {within} from '@testing-library/dom';
1617

1718
interface TriggerCheckboxOptions {
1819
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {act, waitFor, within} from '@testing-library/react';
13+
import {act} from './act';
1414
import {ComboBoxTesterOpts, UserOpts} from './types';
15+
import {waitFor, within} from '@testing-library/dom';
1516

1617
interface ComboBoxOpenOpts {
1718
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {act, waitFor, within} from '@testing-library/react';
13+
import {act} from './act';
1414
import {DialogTesterOpts, UserOpts} from './types';
15+
import {waitFor, within} from '@testing-library/dom';
1516

1617
interface DialogOpenOpts {
1718
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {act, fireEvent} from '@testing-library/react';
13+
import {act} from './act';
14+
import {fireEvent} from '@testing-library/dom';
1415
import {UserOpts} from './types';
1516

1617
export const DEFAULT_LONG_PRESS_TIME = 500;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {act, within} from '@testing-library/react';
13+
import {act} from './act';
1414
import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';
1515
import {GridListTesterOpts, GridRowActionOpts, ToggleGridRowOpts, UserOpts} from './types';
16+
import {within} from '@testing-library/dom';
1617

1718
interface GridListToggleRowOpts extends ToggleGridRowOpts {}
1819
interface GridListRowActionOpts extends GridRowActionOpts {}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {act, within} from '@testing-library/react';
13+
import {act} from './act';
1414
import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';
1515
import {ListBoxTesterOpts, UserOpts} from './types';
16+
import {within} from '@testing-library/dom';
1617

1718
interface ListBoxToggleOptionOpts {
1819
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {act, waitFor, within} from '@testing-library/react';
13+
import {act} from './act';
1414
import {MenuTesterOpts, UserOpts} from './types';
1515
import {triggerLongPress} from './events';
16+
import {waitFor, within} from '@testing-library/dom';
1617

1718
interface MenuOpenOpts {
1819
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {act, within} from '@testing-library/react';
13+
import {act} from './act';
1414
import {Direction, Orientation, RadioGroupTesterOpts, UserOpts} from './types';
1515
import {pressElement} from './events';
16+
import {within} from '@testing-library/dom';
1617

1718
interface TriggerRadioOptions {
1819
/**

0 commit comments

Comments
 (0)