diff --git a/packages/@react-aria/test-utils/package.json b/packages/@react-aria/test-utils/package.json index 4393a60b129..c69f6b4b80a 100644 --- a/packages/@react-aria/test-utils/package.json +++ b/packages/@react-aria/test-utils/package.json @@ -29,6 +29,7 @@ "@swc/helpers": "^0.5.0" }, "peerDependencies": { + "@testing-library/dom": "^10.1.0", "@testing-library/react": "^16.0.0", "@testing-library/user-event": "^14.0.0", "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1", diff --git a/packages/@react-aria/test-utils/src/act.ts b/packages/@react-aria/test-utils/src/act.ts new file mode 100644 index 00000000000..e4f35719b89 --- /dev/null +++ b/packages/@react-aria/test-utils/src/act.ts @@ -0,0 +1,23 @@ +/* + * Copyright 2025 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +import * as React from 'react'; +import * as ReactDOMTestUtils from 'react-dom/test-utils'; + +let actImpl: typeof ReactDOMTestUtils.act; +if (typeof React.act === 'function') { + actImpl = React.act; +} else { + actImpl = ReactDOMTestUtils.act; +} + +export const act = actImpl; diff --git a/packages/@react-aria/test-utils/src/checkboxgroup.ts b/packages/@react-aria/test-utils/src/checkboxgroup.ts index 54e436a5cab..6843d4ff9a0 100644 --- a/packages/@react-aria/test-utils/src/checkboxgroup.ts +++ b/packages/@react-aria/test-utils/src/checkboxgroup.ts @@ -10,9 +10,10 @@ * governing permissions and limitations under the License. */ -import {act, within} from '@testing-library/react'; +import {act} from './act'; import {CheckboxGroupTesterOpts, UserOpts} from './types'; import {pressElement} from './events'; +import {within} from '@testing-library/dom'; interface TriggerCheckboxOptions { /** diff --git a/packages/@react-aria/test-utils/src/combobox.ts b/packages/@react-aria/test-utils/src/combobox.ts index d95ac6f5711..5d458fcd933 100644 --- a/packages/@react-aria/test-utils/src/combobox.ts +++ b/packages/@react-aria/test-utils/src/combobox.ts @@ -10,8 +10,9 @@ * governing permissions and limitations under the License. */ -import {act, waitFor, within} from '@testing-library/react'; +import {act} from './act'; import {ComboBoxTesterOpts, UserOpts} from './types'; +import {waitFor, within} from '@testing-library/dom'; interface ComboBoxOpenOpts { /** diff --git a/packages/@react-aria/test-utils/src/dialog.ts b/packages/@react-aria/test-utils/src/dialog.ts index 213c86c2b1a..0c0dd85605c 100644 --- a/packages/@react-aria/test-utils/src/dialog.ts +++ b/packages/@react-aria/test-utils/src/dialog.ts @@ -10,8 +10,9 @@ * governing permissions and limitations under the License. */ -import {act, waitFor, within} from '@testing-library/react'; +import {act} from './act'; import {DialogTesterOpts, UserOpts} from './types'; +import {waitFor, within} from '@testing-library/dom'; interface DialogOpenOpts { /** diff --git a/packages/@react-aria/test-utils/src/events.ts b/packages/@react-aria/test-utils/src/events.ts index e603111d3ea..28364b4d464 100644 --- a/packages/@react-aria/test-utils/src/events.ts +++ b/packages/@react-aria/test-utils/src/events.ts @@ -10,7 +10,8 @@ * governing permissions and limitations under the License. */ -import {act, fireEvent} from '@testing-library/react'; +import {act} from './act'; +import {fireEvent} from '@testing-library/dom'; import {UserOpts} from './types'; export const DEFAULT_LONG_PRESS_TIME = 500; diff --git a/packages/@react-aria/test-utils/src/gridlist.ts b/packages/@react-aria/test-utils/src/gridlist.ts index d5d1c21e082..55012e3f1a1 100644 --- a/packages/@react-aria/test-utils/src/gridlist.ts +++ b/packages/@react-aria/test-utils/src/gridlist.ts @@ -10,9 +10,10 @@ * governing permissions and limitations under the License. */ -import {act, within} from '@testing-library/react'; +import {act} from './act'; import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events'; import {GridListTesterOpts, GridRowActionOpts, ToggleGridRowOpts, UserOpts} from './types'; +import {within} from '@testing-library/dom'; interface GridListToggleRowOpts extends ToggleGridRowOpts {} interface GridListRowActionOpts extends GridRowActionOpts {} diff --git a/packages/@react-aria/test-utils/src/listbox.ts b/packages/@react-aria/test-utils/src/listbox.ts index cac8d9d78bc..fa3649c27e8 100644 --- a/packages/@react-aria/test-utils/src/listbox.ts +++ b/packages/@react-aria/test-utils/src/listbox.ts @@ -10,9 +10,10 @@ * governing permissions and limitations under the License. */ -import {act, within} from '@testing-library/react'; +import {act} from './act'; import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events'; import {ListBoxTesterOpts, UserOpts} from './types'; +import {within} from '@testing-library/dom'; interface ListBoxToggleOptionOpts { /** diff --git a/packages/@react-aria/test-utils/src/menu.ts b/packages/@react-aria/test-utils/src/menu.ts index 87af5c11fd0..1badcd3f539 100644 --- a/packages/@react-aria/test-utils/src/menu.ts +++ b/packages/@react-aria/test-utils/src/menu.ts @@ -10,9 +10,10 @@ * governing permissions and limitations under the License. */ -import {act, waitFor, within} from '@testing-library/react'; +import {act} from './act'; import {MenuTesterOpts, UserOpts} from './types'; import {triggerLongPress} from './events'; +import {waitFor, within} from '@testing-library/dom'; interface MenuOpenOpts { /** diff --git a/packages/@react-aria/test-utils/src/radiogroup.ts b/packages/@react-aria/test-utils/src/radiogroup.ts index 6c1d0e38c9e..fc94e187c8f 100644 --- a/packages/@react-aria/test-utils/src/radiogroup.ts +++ b/packages/@react-aria/test-utils/src/radiogroup.ts @@ -10,9 +10,10 @@ * governing permissions and limitations under the License. */ -import {act, within} from '@testing-library/react'; +import {act} from './act'; import {Direction, Orientation, RadioGroupTesterOpts, UserOpts} from './types'; import {pressElement} from './events'; +import {within} from '@testing-library/dom'; interface TriggerRadioOptions { /** diff --git a/packages/@react-aria/test-utils/src/select.ts b/packages/@react-aria/test-utils/src/select.ts index 4cce164f53f..f4b3b8ac432 100644 --- a/packages/@react-aria/test-utils/src/select.ts +++ b/packages/@react-aria/test-utils/src/select.ts @@ -10,8 +10,9 @@ * governing permissions and limitations under the License. */ -import {act, waitFor, within} from '@testing-library/react'; +import {act} from './act'; import {SelectTesterOpts, UserOpts} from './types'; +import {waitFor, within} from '@testing-library/dom'; interface SelectOpenOpts { /** diff --git a/packages/@react-aria/test-utils/src/table.ts b/packages/@react-aria/test-utils/src/table.ts index 2401beeed1b..661fdd4a5dc 100644 --- a/packages/@react-aria/test-utils/src/table.ts +++ b/packages/@react-aria/test-utils/src/table.ts @@ -10,9 +10,10 @@ * governing permissions and limitations under the License. */ -import {act, waitFor, within} from '@testing-library/react'; +import {act} from './act'; import {BaseGridRowInteractionOpts, GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types'; import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events'; +import {waitFor, within} from '@testing-library/dom'; interface TableToggleRowOpts extends ToggleGridRowOpts {} interface TableToggleExpansionOpts extends BaseGridRowInteractionOpts {} diff --git a/packages/@react-aria/test-utils/src/tabs.ts b/packages/@react-aria/test-utils/src/tabs.ts index c26da3e7656..9647b8c8937 100644 --- a/packages/@react-aria/test-utils/src/tabs.ts +++ b/packages/@react-aria/test-utils/src/tabs.ts @@ -10,9 +10,10 @@ * governing permissions and limitations under the License. */ -import {act, within} from '@testing-library/react'; +import {act} from './act'; import {Direction, Orientation, TabsTesterOpts, UserOpts} from './types'; import {pressElement} from './events'; +import {within} from '@testing-library/dom'; interface TriggerTabOptions { /** diff --git a/packages/@react-aria/test-utils/src/tree.ts b/packages/@react-aria/test-utils/src/tree.ts index cadcf52b72a..6270ca5d572 100644 --- a/packages/@react-aria/test-utils/src/tree.ts +++ b/packages/@react-aria/test-utils/src/tree.ts @@ -10,9 +10,10 @@ * governing permissions and limitations under the License. */ -import {act, within} from '@testing-library/react'; +import {act} from './act'; import {BaseGridRowInteractionOpts, GridRowActionOpts, ToggleGridRowOpts, TreeTesterOpts, UserOpts} from './types'; import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events'; +import {within} from '@testing-library/dom'; interface TreeToggleExpansionOpts extends BaseGridRowInteractionOpts {} interface TreeToggleRowOpts extends ToggleGridRowOpts {} diff --git a/packages/@react-spectrum/test-utils/package.json b/packages/@react-spectrum/test-utils/package.json index 6e5c4ce0b18..3fcac8279a0 100644 --- a/packages/@react-spectrum/test-utils/package.json +++ b/packages/@react-spectrum/test-utils/package.json @@ -32,6 +32,7 @@ "@swc/helpers": "^0.5.0" }, "peerDependencies": { + "@testing-library/dom": "^10.1.0", "@testing-library/react": "^16.0.0", "@testing-library/user-event": "^14.0.0", "jest": "^29.5.0", diff --git a/yarn.lock b/yarn.lock index 0d63538a20f..eb4a90824b7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6190,6 +6190,7 @@ __metadata: dependencies: "@swc/helpers": "npm:^0.5.0" peerDependencies: + "@testing-library/dom": ^10.1.0 "@testing-library/react": ^16.0.0 "@testing-library/user-event": ^14.0.0 react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1 @@ -7809,6 +7810,7 @@ __metadata: "@react-aria/test-utils": "npm:1.0.0-beta.2" "@swc/helpers": "npm:^0.5.0" peerDependencies: + "@testing-library/dom": ^10.1.0 "@testing-library/react": ^16.0.0 "@testing-library/user-event": ^14.0.0 jest: ^29.5.0