diff --git a/.eslintrc.js b/.eslintrc.js
index 0fc37713dce4d..c4f14b6a45907 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -459,13 +459,27 @@ module.exports = {
// the `@wordpress/components` package, hence why importing those
// dependencies should be allowed in the components package.
{
- paths: restrictedImports.filter(
- ( { name } ) =>
- ! [
- '@ariakit/react',
- 'framer-motion',
- ].includes( name )
- ),
+ paths: [
+ ...restrictedImports.filter(
+ ( { name } ) =>
+ ! [
+ '@ariakit/react',
+ 'framer-motion',
+ ].includes( name )
+ ),
+ // TODO: enable this rule in the future.
+ // {
+ // name: '@testing-library/user-event',
+ // message:
+ // 'Please use event triggers (`click`, `press`, etc) from `@ariakit/test` instead.',
+ // },
+ {
+ name: '@testing-library/react',
+ importNames: [ 'render' ],
+ message:
+ 'Please use `render` from `@ariakit/test` instead.',
+ },
+ ],
},
],
},
diff --git a/migration/migrate.sh b/migration/migrate.sh
new file mode 100755
index 0000000000000..857ce9a8ced15
--- /dev/null
+++ b/migration/migrate.sh
@@ -0,0 +1,16 @@
+# HOW TO RUN THIS SCRIPT
+#
+# 1. Install grit (https://docs.grit.io/cli/quickstart#installation):
+# $ npm install --location=global @getgrit/cli
+#
+# 2. Run this script from the root of the project (<- IMPORTANT):
+# $ ./migration/migrate.sh
+
+function apply() {
+ grit apply --force --output none "migration/patterns/$1.grit" packages/components
+}
+
+apply await_render_calls
+apply replace_ariakit_test_import
+git checkout '*.native.*'
+npm run lint:js:fix -- packages/components
diff --git a/migration/patterns/await_render_calls.grit b/migration/patterns/await_render_calls.grit
new file mode 100644
index 0000000000000..1d85793712b6e
--- /dev/null
+++ b/migration/patterns/await_render_calls.grit
@@ -0,0 +1,21 @@
+engine marzano(0.1)
+language js
+
+pattern await_render_calls() {
+ `it($description, $test_fn)` where {
+ $test_fn <: contains bubble `$render_method($render_args)` where {
+ !$render_method <: within `await $_`,
+ $render_method <: or {
+ `render` => `await render`,
+ `rerender` => `await rerender`
+ },
+ },
+ $test_fn <: maybe $test_fn where {
+ !$test_fn <: arrow_function(async = "async"),
+ !$test_fn <: function(async = "async"),
+ $test_fn => `async $test_fn`
+ }
+ }
+}
+
+await_render_calls()
diff --git a/migration/patterns/replace_ariakit_test_import.grit b/migration/patterns/replace_ariakit_test_import.grit
new file mode 100644
index 0000000000000..fdebc26e00f90
--- /dev/null
+++ b/migration/patterns/replace_ariakit_test_import.grit
@@ -0,0 +1,14 @@
+engine marzano(0.1)
+language js
+
+pattern replace_ariakit_test_import() {
+ `import { $imports } from '@testing-library/react'` as $import where {
+ $imports <: contains `render` as $render,
+ $render => .,
+ $import =>
+`$import;
+import {render} from "@ariakit/test/react";`
+ }
+}
+
+replace_ariakit_test_import()
diff --git a/packages/components/src/alignment-matrix-control/test/index.tsx b/packages/components/src/alignment-matrix-control/test/index.tsx
index a820b69b26c8f..f656619b252b7 100644
--- a/packages/components/src/alignment-matrix-control/test/index.tsx
+++ b/packages/components/src/alignment-matrix-control/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, waitFor, within } from '@testing-library/react';
+import { screen, waitFor, within } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import { press, click } from '@ariakit/test';
/**
diff --git a/packages/components/src/autocomplete/test/index.tsx b/packages/components/src/autocomplete/test/index.tsx
index 0df784f8367cd..90207e6d8c745 100644
--- a/packages/components/src/autocomplete/test/index.tsx
+++ b/packages/components/src/autocomplete/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -82,7 +83,7 @@ describe( 'AutocompleterUI', () => {
);
};
- render( );
+ await render( );
// Click on autocompleter.
await user.click( screen.getByText( 'Apple' ) );
diff --git a/packages/components/src/base-control/test/index.tsx b/packages/components/src/base-control/test/index.tsx
index 07623a8b4c3e7..62961a005852c 100644
--- a/packages/components/src/base-control/test/index.tsx
+++ b/packages/components/src/base-control/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -21,8 +22,8 @@ const MyBaseControl = ( props: Omit< BaseControlProps, 'children' > ) => {
};
describe( 'BaseControl', () => {
- it( 'should render help text as description', () => {
- render( );
+ it( 'should render help text as description', async () => {
+ await render( );
expect(
screen.getByRole( 'textbox', {
@@ -31,8 +32,8 @@ describe( 'BaseControl', () => {
).toBeInTheDocument();
} );
- it( 'should still render help as aria-describedby when not plain text', () => {
- render(
+ it( 'should still render help as aria-describedby when not plain text', async () => {
+ await render(
My help text }
diff --git a/packages/components/src/border-box-control/test/index.tsx b/packages/components/src/border-box-control/test/index.tsx
index fe5f7e7a4f1ff..9f0ae0e3fa56e 100644
--- a/packages/components/src/border-box-control/test/index.tsx
+++ b/packages/components/src/border-box-control/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, waitFor } from '@testing-library/react';
+import { screen, waitFor } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -51,8 +52,8 @@ const colorPickerRegex = /Border color picker/;
describe( 'BorderBoxControl', () => {
describe( 'Linked view rendering', () => {
- it( 'should render correctly when no value provided', () => {
- render( );
+ it( 'should render correctly when no value provided', async () => {
+ await render( );
const label = screen.getByText( props.label );
const colorButton = screen.getByLabelText( toggleLabelRegex );
@@ -76,8 +77,10 @@ describe( 'BorderBoxControl', () => {
expect( linkedButton ).toBeInTheDocument();
} );
- it( 'should hide label', () => {
- render( );
+ it( 'should hide label', async () => {
+ await render(
+
+ );
const label = screen.getByText( props.label );
@@ -90,8 +93,10 @@ describe( 'BorderBoxControl', () => {
);
} );
- it( 'should show correct width value when flat border value provided', () => {
- render( );
+ it( 'should show correct width value when flat border value provided', async () => {
+ await render(
+
+ );
const widthInput = screen.getByRole( 'spinbutton', {
name: 'Border width',
@@ -100,8 +105,8 @@ describe( 'BorderBoxControl', () => {
expect( widthInput.value ).toBe( '1' );
} );
- it( 'should show correct width value when consistent split borders provided', () => {
- render(
+ it( 'should show correct width value when consistent split borders provided', async () => {
+ await render(
);
@@ -115,7 +120,9 @@ describe( 'BorderBoxControl', () => {
it( 'should render placeholder and omit unit select when border values are mixed', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
// There are 4 inputs when in unlinked mode (top/right/bottom/left)
expect(
@@ -153,7 +160,7 @@ describe( 'BorderBoxControl', () => {
const user = userEvent.setup();
// Render control with mixed border values but consistent widths.
- render(
+ await render(
{
it( 'should omit style options when requested', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const colorButton = screen.getByLabelText( colorPickerRegex );
await user.click( colorButton );
@@ -218,8 +227,10 @@ describe( 'BorderBoxControl', () => {
} );
describe( 'Split view rendering', () => {
- it( 'should render split view by default when mixed values provided', () => {
- render( );
+ it( 'should render split view by default when mixed values provided', async () => {
+ await render(
+
+ );
const colorButtons = screen.getAllByLabelText( toggleLabelRegex );
const widthInputs = screen.getAllByRole( 'spinbutton', {
@@ -240,8 +251,10 @@ describe( 'BorderBoxControl', () => {
expect( linkedButton ).toBeInTheDocument();
} );
- it( 'should render correct width values in appropriate inputs', () => {
- render( );
+ it( 'should render correct width values in appropriate inputs', async () => {
+ await render(
+
+ );
const widthInputs = screen.getAllByRole( 'spinbutton', {
name: 'Border width',
@@ -256,7 +269,7 @@ describe( 'BorderBoxControl', () => {
it( 'should render split view correctly when starting with flat border', async () => {
const user = userEvent.setup();
- render(
+ await render(
);
@@ -316,7 +329,7 @@ describe( 'BorderBoxControl', () => {
it( 'should set undefined when new border is empty', async () => {
const user = userEvent.setup();
- render(
+ await render(
);
@@ -330,7 +343,7 @@ describe( 'BorderBoxControl', () => {
it( 'should update with complete flat border', async () => {
const user = userEvent.setup();
- render(
+ await render(
);
@@ -349,7 +362,7 @@ describe( 'BorderBoxControl', () => {
it( 'should maintain mixed values if not explicitly set via linked control', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
it( 'should update with consistent split borders', async () => {
const user = userEvent.setup();
- render(
+ await render(
);
@@ -401,7 +414,7 @@ describe( 'BorderBoxControl', () => {
it( 'should set undefined borders when change results in empty borders', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
it( 'should set flat border when change results in consistent split borders', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
left: { ...defaultBorder, width: '4px' },
};
- render( );
+ await render(
+
+ );
const widthInput = screen.getAllByRole( 'spinbutton', {
name: 'Border width',
@@ -487,7 +502,9 @@ describe( 'BorderBoxControl', () => {
left: { ...defaultBorder, width: '1px' },
};
- render( );
+ await render(
+
+ );
const widthInput = screen.getAllByRole( 'spinbutton', {
name: 'Border width',
diff --git a/packages/components/src/border-control/test/index.js b/packages/components/src/border-control/test/index.js
index c41dce687cc52..0daa269f730a8 100644
--- a/packages/components/src/border-control/test/index.js
+++ b/packages/components/src/border-control/test/index.js
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { fireEvent, screen, waitFor } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -72,9 +73,9 @@ const getWidthInput = () => {
describe( 'BorderControl', () => {
describe( 'basic rendering', () => {
- it( 'should render standard border control', () => {
+ it( 'should render standard border control', async () => {
const props = createProps();
- render( );
+ await render( );
const label = screen.getByText( props.label );
const colorButton = screen.getByLabelText( toggleLabelRegex );
@@ -93,9 +94,9 @@ describe( 'BorderControl', () => {
expect( slider ).not.toBeInTheDocument();
} );
- it( 'should hide label', () => {
+ it( 'should hide label', async () => {
const props = createProps( { hideLabelFromVision: true } );
- render( );
+ await render( );
const label = screen.getByText( props.label );
// As visually hidden labels are still included in the document
@@ -107,17 +108,17 @@ describe( 'BorderControl', () => {
);
} );
- it( 'should render with slider', () => {
+ it( 'should render with slider', async () => {
const props = createProps( { withSlider: true } );
- render( );
+ await render( );
const slider = getSliderInput();
expect( slider ).toBeInTheDocument();
} );
- it( 'should render placeholder in UnitControl', () => {
+ it( 'should render placeholder in UnitControl', async () => {
const props = createProps( { placeholder: 'Mixed' } );
- render( );
+ await render( );
const widthInput = getWidthInput();
expect( widthInput ).toHaveAttribute( 'placeholder', 'Mixed' );
@@ -126,7 +127,7 @@ describe( 'BorderControl', () => {
it( 'should render color and style popover', async () => {
const user = userEvent.setup();
const props = createProps();
- render( );
+ await render( );
await openPopover( user );
const customColorPicker = getButton( /Custom color picker/ );
@@ -151,7 +152,7 @@ describe( 'BorderControl', () => {
it( 'should render color and style popover header', async () => {
const user = userEvent.setup();
const props = createProps( { showDropdownHeader: true } );
- render( );
+ await render( );
await openPopover( user );
const headerLabel = screen.getByText( 'Border color' );
@@ -164,7 +165,7 @@ describe( 'BorderControl', () => {
it( 'should not render style options when opted out of', async () => {
const user = userEvent.setup();
const props = createProps( { enableStyle: false } );
- render( );
+ await render( );
await openPopover( user );
const styleLabel = screen.queryByText( 'Style' );
@@ -181,18 +182,18 @@ describe( 'BorderControl', () => {
describe( 'color and style picker aria labels', () => {
describe( 'with style selection enabled', () => {
- it( 'should include both color and style in label', () => {
+ it( 'should include both color and style in label', async () => {
const props = createProps( { value: undefined } );
- render( );
+ await render( );
expect(
screen.getByLabelText( 'Border color and style picker.' )
).toBeInTheDocument();
} );
- it( 'should correctly describe named color selection', () => {
+ it( 'should correctly describe named color selection', async () => {
const props = createProps( { value: { color: '#72aee6' } } );
- render( );
+ await render( );
expect(
screen.getByLabelText(
@@ -201,9 +202,9 @@ describe( 'BorderControl', () => {
).toBeInTheDocument();
} );
- it( 'should correctly describe custom color selection', () => {
+ it( 'should correctly describe custom color selection', async () => {
const props = createProps( { value: { color: '#4b1d80' } } );
- render( );
+ await render( );
expect(
screen.getByLabelText(
@@ -212,11 +213,11 @@ describe( 'BorderControl', () => {
).toBeInTheDocument();
} );
- it( 'should correctly describe named color and style selections', () => {
+ it( 'should correctly describe named color and style selections', async () => {
const props = createProps( {
value: { color: '#72aee6', style: 'dotted' },
} );
- render( );
+ await render( );
expect(
screen.getByLabelText(
@@ -225,11 +226,11 @@ describe( 'BorderControl', () => {
).toBeInTheDocument();
} );
- it( 'should correctly describe custom color and style selections', () => {
+ it( 'should correctly describe custom color and style selections', async () => {
const props = createProps( {
value: { color: '#4b1d80', style: 'dashed' },
} );
- render( );
+ await render( );
expect(
screen.getByLabelText(
@@ -240,24 +241,24 @@ describe( 'BorderControl', () => {
} );
describe( 'with style selection disabled', () => {
- it( 'should only include color in the label', () => {
+ it( 'should only include color in the label', async () => {
const props = createProps( {
value: undefined,
enableStyle: false,
} );
- render( );
+ await render( );
expect(
screen.getByLabelText( 'Border color picker.' )
).toBeInTheDocument();
} );
- it( 'should correctly describe named color selection', () => {
+ it( 'should correctly describe named color selection', async () => {
const props = createProps( {
value: { color: '#72aee6' },
enableStyle: false,
} );
- render( );
+ await render( );
expect(
screen.getByLabelText(
@@ -266,12 +267,12 @@ describe( 'BorderControl', () => {
).toBeInTheDocument();
} );
- it( 'should correctly describe custom color selection', () => {
+ it( 'should correctly describe custom color selection', async () => {
const props = createProps( {
value: { color: '#4b1d80' },
enableStyle: false,
} );
- render( );
+ await render( );
expect(
screen.getByLabelText(
@@ -283,9 +284,9 @@ describe( 'BorderControl', () => {
} );
describe( 'onChange handling', () => {
- it( 'should update width with slider value', () => {
+ it( 'should update width with slider value', async () => {
const props = createProps( { withSlider: true } );
- const { rerender } = render( );
+ const { rerender } = await render( );
const slider = getSliderInput();
// As per [1], it is not currently possible to reasonably
@@ -299,7 +300,7 @@ describe( 'BorderControl', () => {
width: '5px',
} );
- rerender( );
+ await rerender( );
const widthInput = getWidthInput();
expect( widthInput.value ).toEqual( '5' );
@@ -308,7 +309,7 @@ describe( 'BorderControl', () => {
it( 'should update color selection', async () => {
const user = userEvent.setup();
const props = createProps();
- render( );
+ await render( );
await openPopover( user );
await user.click( getColorOption( 'Green' ) );
@@ -321,7 +322,7 @@ describe( 'BorderControl', () => {
it( 'should clear color selection when toggling swatch off', async () => {
const user = userEvent.setup();
const props = createProps();
- render( );
+ await render( );
await openPopover( user );
await user.click( getColorOption( 'Blue' ) );
@@ -334,7 +335,7 @@ describe( 'BorderControl', () => {
it( 'should update style selection', async () => {
const user = userEvent.setup();
const props = createProps();
- render( );
+ await render( );
await openPopover( user );
await user.click( getButton( 'Dashed' ) );
@@ -347,7 +348,7 @@ describe( 'BorderControl', () => {
it( 'should take no action when color and style popover is closed', async () => {
const user = userEvent.setup();
const props = createProps( { showDropdownHeader: true } );
- render( );
+ await render( );
await openPopover( user );
await user.click( getButton( 'Close border color' ) );
@@ -357,7 +358,7 @@ describe( 'BorderControl', () => {
it( 'should reset color and style only when popover reset button clicked', async () => {
const user = userEvent.setup();
const props = createProps();
- render( );
+ await render( );
await openPopover( user );
await user.click( getButton( 'Reset' ) );
@@ -371,9 +372,9 @@ describe( 'BorderControl', () => {
it( 'should sanitize border when width and color are undefined', async () => {
const user = userEvent.setup();
const props = createProps();
- const { rerender } = render( );
+ const { rerender } = await render( );
await user.clear( getWidthInput() );
- rerender( );
+ await rerender( );
await openPopover( user );
await user.click( getColorOption( 'Blue' ) );
@@ -385,9 +386,9 @@ describe( 'BorderControl', () => {
const props = createProps( {
shouldSanitizeBorder: false,
} );
- const { rerender } = render( );
+ const { rerender } = await render( );
await user.clear( getWidthInput() );
- rerender( );
+ await rerender( );
await openPopover( user );
await user.click( getColorOption( 'Blue' ) );
@@ -401,7 +402,7 @@ describe( 'BorderControl', () => {
it( 'should clear color and set style to `none` when setting zero width', async () => {
const user = userEvent.setup();
const props = createProps();
- render( );
+ await render( );
await openPopover( user );
await user.click( getColorOption( 'Green' ) );
await user.click( getButton( 'Dotted' ) );
@@ -420,12 +421,12 @@ describe( 'BorderControl', () => {
it( 'should reselect color and style selections when changing to non-zero width', async () => {
const user = userEvent.setup();
const props = createProps();
- const { rerender } = render( );
+ const { rerender } = await render( );
await openPopover( user );
await user.click( getColorOption( 'Green' ) );
- rerender( );
+ await rerender( );
await user.click( getButton( 'Dotted' ) );
- rerender( );
+ await rerender( );
const widthInput = getWidthInput();
await user.type( widthInput, '0', {
initialSelectionStart: 0,
@@ -446,7 +447,7 @@ describe( 'BorderControl', () => {
it( 'should set a non-zero width when applying color to zero width border', async () => {
const user = userEvent.setup();
const props = createProps( { value: undefined } );
- const { rerender } = render( );
+ const { rerender } = await render( );
await openPopover( user );
await user.click( getColorOption( 'Yellow' ) );
@@ -458,7 +459,7 @@ describe( 'BorderControl', () => {
await user.type( getWidthInput(), '0' );
- rerender( );
+ await rerender( );
await openPopover( user );
await user.click( getColorOption( 'Green' ) );
@@ -475,7 +476,7 @@ describe( 'BorderControl', () => {
value: undefined,
shouldSanitizeBorder: false,
} );
- const { rerender } = render( );
+ const { rerender } = await render( );
await openPopover( user );
await user.click( getButton( 'Dashed' ) );
@@ -487,7 +488,7 @@ describe( 'BorderControl', () => {
await user.type( getWidthInput(), '0' );
- rerender( );
+ await rerender( );
await openPopover( user );
await user.click( getButton( 'Dotted' ) );
diff --git a/packages/components/src/box-control/test/index.tsx b/packages/components/src/box-control/test/index.tsx
index 681e7721d0c13..6475c068e86b5 100644
--- a/packages/components/src/box-control/test/index.tsx
+++ b/packages/components/src/box-control/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { fireEvent, render, screen } from '@testing-library/react';
+import { fireEvent, screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -29,8 +30,8 @@ const Example = ( extraProps: Omit< BoxControlProps, 'onChange' > ) => {
describe( 'BoxControl', () => {
describe( 'Basic rendering', () => {
- it( 'should render a box control input', () => {
- render( {} } /> );
+ it( 'should render a box control input', async () => {
+ await render( {} } /> );
expect(
screen.getByRole( 'group', { name: 'Box Control' } )
@@ -43,7 +44,7 @@ describe( 'BoxControl', () => {
it( 'should update values when interacting with input', async () => {
const user = userEvent.setup();
- render( {} } /> );
+ await render( {} } /> );
const input = screen.getByRole( 'textbox', { name: 'All sides' } );
@@ -53,8 +54,8 @@ describe( 'BoxControl', () => {
expect( input ).toHaveValue( '100' );
} );
- it( 'should update input values when interacting with slider', () => {
- render( {} } /> );
+ it( 'should update input values when interacting with slider', async () => {
+ await render( {} } /> );
const slider = screen.getByRole( 'slider' );
@@ -68,7 +69,7 @@ describe( 'BoxControl', () => {
it( 'should update slider values when interacting with input', async () => {
const user = userEvent.setup();
- render( {} } /> );
+ await render( {} } /> );
const input = screen.getByRole( 'textbox', {
name: 'All sides',
@@ -81,16 +82,16 @@ describe( 'BoxControl', () => {
expect( screen.getByRole( 'slider' ) ).toHaveValue( '50' );
} );
- it( 'should render the number input with a default min value of 0', () => {
- render( {} } /> );
+ it( 'should render the number input with a default min value of 0', async () => {
+ await render( {} } /> );
const input = screen.getByRole( 'textbox', { name: 'All sides' } );
expect( input ).toHaveAttribute( 'min', '0' );
} );
- it( 'should pass down `inputProps` to the underlying number input', () => {
- render(
+ it( 'should pass down `inputProps` to the underlying number input', async () => {
+ await render(
{} }
inputProps={ { min: 10, max: 50 } }
@@ -108,7 +109,7 @@ describe( 'BoxControl', () => {
it( 'should reset values when clicking Reset', async () => {
const user = userEvent.setup();
- render( {} } /> );
+ await render( {} } /> );
const input = screen.getByRole( 'textbox', {
name: 'All sides',
@@ -127,7 +128,7 @@ describe( 'BoxControl', () => {
it( 'should reset values when clicking Reset, if controlled', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'textbox', {
name: 'All sides',
@@ -146,7 +147,7 @@ describe( 'BoxControl', () => {
it( 'should reset values when clicking Reset, if controlled <-> uncontrolled state changes', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'textbox', {
name: 'All sides',
@@ -166,7 +167,7 @@ describe( 'BoxControl', () => {
const user = userEvent.setup();
const spyChange = jest.fn();
- render( spyChange( v ) } /> );
+ await render( spyChange( v ) } /> );
const input = screen.getByRole( 'textbox', {
name: 'All sides',
@@ -196,7 +197,7 @@ describe( 'BoxControl', () => {
it( 'should update a single side value when unlinked', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
await user.click(
screen.getByRole( 'button', { name: 'Unlink sides' } )
@@ -224,7 +225,7 @@ describe( 'BoxControl', () => {
it( 'should update a single side value when using slider unlinked', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
await user.click(
screen.getByRole( 'button', { name: 'Unlink sides' } )
@@ -252,7 +253,7 @@ describe( 'BoxControl', () => {
it( 'should update a whole axis when value is changed when unlinked', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
await user.click(
screen.getByRole( 'button', { name: 'Unlink sides' } )
@@ -276,7 +277,7 @@ describe( 'BoxControl', () => {
it( 'should update a whole axis using a slider when value is changed when unlinked', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
await user.click(
screen.getByRole( 'button', { name: 'Unlink sides' } )
@@ -300,7 +301,7 @@ describe( 'BoxControl', () => {
it( 'should show "Mixed" label when sides have different values but are linked', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const unlinkButton = screen.getByRole( 'button', {
name: 'Unlink sides',
@@ -330,7 +331,7 @@ describe( 'BoxControl', () => {
const user = userEvent.setup();
// Render control.
- render( {} } /> );
+ await render( {} } /> );
// Make unit selection on all input control.
await user.selectOptions(
@@ -362,7 +363,9 @@ describe( 'BoxControl', () => {
const user = userEvent.setup();
// Render control.
- const { rerender } = render( {} } /> );
+ const { rerender } = await render(
+ {} } />
+ );
// Make unit selection on all input control.
await user.selectOptions(
@@ -390,7 +393,7 @@ describe( 'BoxControl', () => {
} );
// Rerender with individual side value & confirm unit is selected.
- rerender(
+ await rerender(
{} } />
);
@@ -414,7 +417,7 @@ describe( 'BoxControl', () => {
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render( );
+ await render( );
const valueInput = screen.getByRole( 'textbox', {
name: 'All sides',
@@ -443,7 +446,7 @@ describe( 'BoxControl', () => {
const user = userEvent.setup();
const setState = jest.fn();
- render( );
+ await render( );
await user.selectOptions(
screen.getByRole( 'combobox', {
diff --git a/packages/components/src/button/test/index.tsx b/packages/components/src/button/test/index.tsx
index 8161e68c4e21b..091468e65a4c0 100644
--- a/packages/components/src/button/test/index.tsx
+++ b/packages/components/src/button/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* WordPress dependencies
@@ -21,8 +22,8 @@ jest.mock( '../../icon', () => () => );
describe( 'Button', () => {
describe( 'basic rendering', () => {
- it( 'should render a button element with only one class', () => {
- render( );
+ it( 'should render a button element with only one class', async () => {
+ await render( );
const button = screen.getByRole( 'button' );
expect( button ).toHaveClass( 'components-button' );
@@ -34,16 +35,16 @@ describe( 'Button', () => {
expect( button ).toHaveAttribute( 'type', 'button' );
} );
- it( 'should render a button element with is-primary class', () => {
- render( );
+ it( 'should render a button element with is-primary class', async () => {
+ await render( );
const button = screen.getByRole( 'button' );
expect( button ).not.toHaveClass( 'is-large' );
expect( button ).toHaveClass( 'is-primary' );
} );
- it( 'should render a button element with is-secondary and is-small class', () => {
- render( );
+ it( 'should render a button element with is-secondary and is-small class', async () => {
+ await render( );
const button = screen.getByRole( 'button' );
expect( button ).toHaveClass( 'is-secondary' );
@@ -52,8 +53,8 @@ describe( 'Button', () => {
expect( button ).not.toHaveClass( 'is-primary' );
} );
- it( 'should render a button element with is-tertiary class', () => {
- render( );
+ it( 'should render a button element with is-tertiary class', async () => {
+ await render( );
const button = screen.getByRole( 'button' );
expect( button ).not.toHaveClass( 'is-large' );
@@ -62,8 +63,8 @@ describe( 'Button', () => {
expect( button ).toHaveClass( 'is-tertiary' );
} );
- it( 'should render a button element with is-link class', () => {
- render( );
+ it( 'should render a button element with is-link class', async () => {
+ await render( );
const button = screen.getByRole( 'button' );
expect( button ).not.toHaveClass( 'is-primary' );
@@ -73,7 +74,7 @@ describe( 'Button', () => {
} );
it( 'should render a button element with has-text when children are passed', async () => {
- render( );
+ await render( );
// Move focus to the button
await press.Tab();
@@ -81,15 +82,15 @@ describe( 'Button', () => {
expect( screen.getByRole( 'button' ) ).toHaveClass( 'has-text' );
} );
- it( 'should render a button element without has-text when children are not passed', () => {
- render( );
+ it( 'should render a button element without has-text when children are not passed', async () => {
+ await render( );
expect( screen.getByRole( 'button' ) ).not.toHaveClass(
'has-text'
);
} );
- it( 'should render a button element without has-text when children are empty fragment', () => {
- render(
+ it( 'should render a button element without has-text when children are empty fragment', async () => {
+ await render(
@@ -99,8 +100,8 @@ describe( 'Button', () => {
);
} );
- it( 'should render a button element without has-text when a button wrapped in Tooltip', () => {
- render(
+ it( 'should render a button element without has-text when a button wrapped in Tooltip', async () => {
+ await render(
@@ -111,7 +112,7 @@ describe( 'Button', () => {
} );
it( 'should render correctly as a tooltip anchor', async () => {
- render(
+ await render(
<>
@@ -148,7 +149,7 @@ describe( 'Button', () => {
} );
it( 'should render correctly as a tooltip anchor, ignoring its internal tooltip in favour of the external tooltip', async () => {
- render(
+ await render(
<>
@@ -192,7 +193,7 @@ describe( 'Button', () => {
} );
it( 'should not trash the rendered HTML elements when toggling between showing and not showing a tooltip', async () => {
- const { rerender } = render(
+ const { rerender } = await render(
);
@@ -208,7 +209,7 @@ describe( 'Button', () => {
// Re-render the button, but this time change the settings so that it
// shows a tooltip.
- rerender(
+ await rerender(
@@ -219,45 +220,45 @@ describe( 'Button', () => {
expect( button ).toHaveFocus();
// Re-render the button, but stop showing a tooltip.
- rerender( );
+ await rerender( );
// The same button element that we referenced before should still be
// in the document and have focus.
expect( button ).toHaveFocus();
} );
- it( 'should add a disabled prop to the button', () => {
+ it( 'should add a disabled prop to the button', async () => {
// eslint-disable-next-line no-restricted-syntax
- render( );
+ await render( );
expect( screen.getByRole( 'button' ) ).toBeDisabled();
} );
- it( 'should add only aria-disabled attribute when disabled and isFocusable are true', () => {
- render( );
+ it( 'should add only aria-disabled attribute when disabled and isFocusable are true', async () => {
+ await render( );
const button = screen.getByRole( 'button' );
expect( button ).toBeEnabled();
expect( button ).toHaveAttribute( 'aria-disabled' );
} );
- it( 'should not pass the prop target into the element', () => {
+ it( 'should not pass the prop target into the element', async () => {
// @ts-expect-error - `target` requires `href`
- render( );
+ await render( );
expect( screen.getByRole( 'button' ) ).not.toHaveAttribute(
'target'
);
} );
- it( 'should render with an additional className', () => {
- render( );
+ it( 'should render with an additional className', async () => {
+ await render( );
expect( screen.getByRole( 'button' ) ).toHaveClass( 'gutenberg' );
} );
- it( 'should pass additional props to the element', () => {
- render( );
+ it( 'should pass additional props to the element', async () => {
+ await render( );
expect( screen.getByRole( 'button' ) ).toHaveAttribute(
'type',
@@ -265,24 +266,24 @@ describe( 'Button', () => {
);
} );
- it( 'should render an icon button', () => {
- render( );
+ it( 'should render an icon button', async () => {
+ await render( );
const button = screen.getByRole( 'button' );
expect( button ).toHaveClass( 'has-icon' );
expect( button ).not.toHaveAttribute( 'aria-label' );
} );
- it( 'should render a Dashicon component matching the wordpress icon', () => {
- render( );
+ it( 'should render a Dashicon component matching the wordpress icon', async () => {
+ await render( );
expect( screen.getByRole( 'button' ) ).toContainElement(
screen.getByTestId( 'test-icon' )
);
} );
- it( 'should render child elements and icon', () => {
- render(
+ it( 'should render child elements and icon', async () => {
+ await render(
}
@@ -299,7 +300,7 @@ describe( 'Button', () => {
} );
it( 'should add an aria-label when the label property is used, with Tooltip wrapper', async () => {
- render( );
+ await render( );
expect( screen.queryByText( 'WordPress' ) ).not.toBeInTheDocument();
@@ -309,8 +310,8 @@ describe( 'Button', () => {
expect( screen.getByText( 'WordPress' ) ).toBeVisible();
} );
- it( 'should support explicit aria-label override', () => {
- render( );
+ it( 'should support explicit aria-label override', async () => {
+ await render( );
expect( screen.getByRole( 'button' ) ).toHaveAttribute(
'aria-label',
@@ -318,8 +319,8 @@ describe( 'Button', () => {
);
} );
- it( 'should support adding aria-describedby text', () => {
- render( );
+ it( 'should support adding aria-describedby text', async () => {
+ await render( );
expect(
screen.getByRole( 'button', {
description: 'Description text',
@@ -328,7 +329,7 @@ describe( 'Button', () => {
} );
it( 'should populate tooltip with label content for buttons without visible labels (no children)', async () => {
- render(
+ await render(
}>
First item
Second item
@@ -175,7 +177,7 @@ describe( 'DropdownMenu', () => {
} );
it( 'should close when pressing the escape key', async () => {
- render(
+ await render(
Open dropdown }>
Dropdown menu item
@@ -204,7 +206,7 @@ describe( 'DropdownMenu', () => {
} );
it( 'should close when clicking outside of the content', async () => {
- render(
+ await render(
Open dropdown }
@@ -222,7 +224,7 @@ describe( 'DropdownMenu', () => {
} );
it( 'should close when clicking on a menu item', async () => {
- render(
+ await render(
Open dropdown }
@@ -240,7 +242,7 @@ describe( 'DropdownMenu', () => {
} );
it( 'should not close when clicking on a menu item when the `hideOnClick` prop is set to `false`', async () => {
- render(
+ await render(
Open dropdown }
@@ -260,7 +262,7 @@ describe( 'DropdownMenu', () => {
} );
it( 'should not close when clicking on a disabled menu item', async () => {
- render(
+ await render(
Open dropdown }
@@ -280,7 +282,7 @@ describe( 'DropdownMenu', () => {
} );
it( 'should reveal submenu content when hovering over the submenu trigger', async () => {
- render(
+ await render(
Open dropdown }
@@ -325,7 +327,9 @@ describe( 'DropdownMenu', () => {
} );
it( 'should navigate menu items and subitems using the arrow, spacebar and enter keys', async () => {
- render(
+ // TODO: temporarily using the sync version of render until we figure out why it fails when async
+ // see: https://github.com/WordPress/gutenberg/pull/64180
+ renderSync(
Open dropdown }
@@ -479,7 +483,7 @@ describe( 'DropdownMenu', () => {
);
};
- render( );
+ await render( );
// Open dropdown
await click(
@@ -532,7 +536,7 @@ describe( 'DropdownMenu', () => {
it( 'should check radio items and keep the menu open when clicking (uncontrolled)', async () => {
const onRadioValueChangeSpy = jest.fn();
- render(
+ await render(
Open dropdown }>
{
);
};
- render( );
+ await render( );
// Open dropdown
await click(
@@ -739,7 +743,7 @@ describe( 'DropdownMenu', () => {
it( 'should check checkbox items and keep the menu open when clicking (uncontrolled)', async () => {
const onCheckboxValueChangeSpy = jest.fn();
- render(
+ await render(
Open dropdown }>
{
describe( 'modality', () => {
it( 'should be modal by default', async () => {
- render(
+ await render(
<>
Open dropdown }>
Dropdown menu item
@@ -883,7 +887,7 @@ describe( 'DropdownMenu', () => {
} );
it( 'should not be modal when the `modal` prop is set to `false`', async () => {
- render(
+ await render(
<>
Open dropdown }
@@ -921,7 +925,7 @@ describe( 'DropdownMenu', () => {
describe( 'items prefix and suffix', () => {
it( 'should display a prefix on regular items', async () => {
- render(
+ await render(
Open dropdown }>
Item prefix> }>
Dropdown menu item
@@ -945,7 +949,7 @@ describe( 'DropdownMenu', () => {
} );
it( 'should display a suffix on regular items', async () => {
- render(
+ await render(
Open dropdown }>
Item suffix> }>
Dropdown menu item
@@ -969,7 +973,7 @@ describe( 'DropdownMenu', () => {
} );
it( 'should display a suffix on radio items', async () => {
- render(
+ await render(
Open dropdown }>
{
} );
it( 'should display a suffix on checkbox items', async () => {
- render(
+ await render(
Open dropdown }>
{
describe( 'typeahead', () => {
it( 'should highlight matching item', async () => {
- render(
+ await render(
Open dropdown }>
One
Two
@@ -1060,7 +1064,7 @@ describe( 'DropdownMenu', () => {
} );
it( 'should keep previous focus when no matches are found', async () => {
- render(
+ await render(
Open dropdown }>
One
Two
diff --git a/packages/components/src/dropdown-menu/test/index.tsx b/packages/components/src/dropdown-menu/test/index.tsx
index 9bee9f2660508..65f950b0c43e1 100644
--- a/packages/components/src/dropdown-menu/test/index.tsx
+++ b/packages/components/src/dropdown-menu/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, waitFor, within } from '@testing-library/react';
+import { screen, waitFor, within } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -16,15 +17,15 @@ import DropdownMenu from '..';
import MenuItem from '../../menu-item';
describe( 'DropdownMenu', () => {
- it( 'should not render when neither controls nor children are assigned', () => {
- render( );
+ it( 'should not render when neither controls nor children are assigned', async () => {
+ await render( );
// The button toggle should not even be rendered
expect( screen.queryByRole( 'button' ) ).not.toBeInTheDocument();
} );
- it( 'should not render when controls are empty and children is not specified', () => {
- render( );
+ it( 'should not render when controls are empty and children is not specified', async () => {
+ await render( );
// The button toggle should not even be rendered
expect( screen.queryByRole( 'button' ) ).not.toBeInTheDocument();
@@ -56,7 +57,9 @@ describe( 'DropdownMenu', () => {
},
];
- render( );
+ await render(
+
+ );
// Move focus on the toggle button
await user.tab();
@@ -76,7 +79,7 @@ describe( 'DropdownMenu', () => {
it( 'should open menu when pressing arrow down on the toggle and the children prop is used to define menu items', async () => {
const user = userEvent.setup();
- render(
+ await render(
}
diff --git a/packages/components/src/dropdown/test/index.tsx b/packages/components/src/dropdown/test/index.tsx
index c737499c7fb28..99396546bf702 100644
--- a/packages/components/src/dropdown/test/index.tsx
+++ b/packages/components/src/dropdown/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, waitFor } from '@testing-library/react';
+import { screen, waitFor } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -12,7 +13,7 @@ import Dropdown from '..';
describe( 'Dropdown', () => {
it( 'should toggle the dropdown properly', async () => {
const user = userEvent.setup();
- const { unmount } = render(
+ const { unmount } = await render(
{
it( 'should close the dropdown when calling onClose', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
const mockOnChange = jest.fn();
- render( );
+ await render( );
const draggableArea = screen.getByRole( 'button' );
@@ -38,12 +39,12 @@ describe( 'FocalPointPicker', () => {
expect( draggableArea ).toHaveFocus();
} );
- it( 'should stop a drag operation when focus is lost', () => {
+ it( 'should stop a drag operation when focus is lost', async () => {
const mockOnDrag = jest.fn();
const mockOnDragEnd = jest.fn();
const mockOnChange = jest.fn();
- render(
+ await render(
{
} );
describe( 'drag gestures', () => {
- it( 'should call onDragStart, onDrag, onDragEnd and onChange in that order', () => {
+ it( 'should call onDragStart, onDrag, onDragEnd and onChange in that order', async () => {
const logs: Log[] = [];
const eventLogger: EventLogger = ( name, args ) =>
logs.push( { name, args } );
@@ -80,7 +81,7 @@ describe( 'FocalPointPicker', () => {
handlers[ name ] = ( ...all ) => eventLogger( name, all );
} );
- render( );
+ await render( );
const dragArea = screen.getByRole( 'button' );
@@ -105,7 +106,7 @@ describe( 'FocalPointPicker', () => {
const spyChange = jest.fn();
const spy = jest.fn();
- render(
+ await render(
{
} );
describe( 'controllability', () => {
- it( 'should update value from props', () => {
- const { rerender } = render(
+ it( 'should update value from props', async () => {
+ const { rerender } = await render(
);
const xInput = screen.getByRole( 'spinbutton', {
name: 'Focal point left position',
} ) as HTMLButtonElement;
- rerender( );
+ await rerender(
+
+ );
expect( xInput.value ).toBe( '93' );
} );
it( 'call onChange with the expected values', async () => {
const user = userEvent.setup();
const spyChange = jest.fn();
- render(
+ await render(
{
} );
describe( 'value handling', () => {
- it( 'should handle legacy string values', () => {
+ it( 'should handle legacy string values', async () => {
const onChangeSpy = jest.fn();
- render(
+ await render(
{
describe( 'Basic rendering', () => {
- it( 'should render', () => {
- render( );
+ it( 'should render', async () => {
+ await render( );
expect( screen.getByTestId( 'media' ) ).toBeVisible();
} );
} );
describe( 'Media types', () => {
- it( 'should render a placeholder by default', () => {
- render( );
+ it( 'should render a placeholder by default', async () => {
+ await render( );
expect( screen.getByTestId( 'media' ) ).toHaveClass(
'components-focal-point-picker__media--placeholder'
);
} );
- it( 'should render an video if src is a video file', () => {
- const { rerender } = render(
+ it( 'should render an video if src is a video file', async () => {
+ const { rerender } = await render(
);
expect( screen.getByTestId( 'media' ).tagName ).toBe( 'VIDEO' );
- rerender( );
+ await rerender(
+
+ );
expect( screen.getByTestId( 'media' ).tagName ).toBe( 'VIDEO' );
- rerender( );
+ await rerender(
+
+ );
expect( screen.getByTestId( 'media' ).tagName ).toBe( 'VIDEO' );
} );
- it( 'should render an image file, if not video', () => {
- const { rerender } = render(
+ it( 'should render an image file, if not video', async () => {
+ const { rerender } = await render(
);
expect( screen.getByTestId( 'media' ).tagName ).toBe( 'IMG' );
- rerender( );
+ await rerender(
+
+ );
expect( screen.getByTestId( 'media' ).tagName ).toBe( 'IMG' );
} );
diff --git a/packages/components/src/font-size-picker/test/index.tsx b/packages/components/src/font-size-picker/test/index.tsx
index e7205e57eefaa..ed5dffd23247b 100644
--- a/packages/components/src/font-size-picker/test/index.tsx
+++ b/packages/components/src/font-size-picker/test/index.tsx
@@ -551,7 +551,7 @@ describe( 'FontSizePicker', () => {
);
expect( screen.getByLabelText( 'Custom' ) ).toBeVisible();
- rerender(
+ await rerender(
{
);
expect( screen.getByLabelText( 'Custom' ) ).toBeVisible();
- rerender(
+ await rerender(
{
- it( 'should show an Icon Button and a hidden input', () => {
- render(
+ it( 'should show an Icon Button and a hidden input', async () => {
+ await render(
{} }>
My Upload Button
@@ -40,7 +41,7 @@ describe( 'FormFileUpload', () => {
const onChange = jest.fn();
- render(
+ await render(
My Upload Button
@@ -65,7 +66,7 @@ describe( 'FormFileUpload', () => {
const onChange = jest.fn();
- render(
+ await render(
( e.currentTarget.value = '' ) ) }
onChange={ onChange }
diff --git a/packages/components/src/form-toggle/test/index.tsx b/packages/components/src/form-toggle/test/index.tsx
index b843ecc27c74b..833e568834b9b 100644
--- a/packages/components/src/form-toggle/test/index.tsx
+++ b/packages/components/src/form-toggle/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -15,6 +16,12 @@ import { useState } from '@wordpress/element';
import FormToggle, { noop } from '..';
import type { FormToggleProps } from '../types';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
const getInput = () => screen.getByRole( 'checkbox' ) as HTMLInputElement;
const ControlledFormToggle = ( { onChange }: FormToggleProps ) => {
@@ -32,26 +39,30 @@ const ControlledFormToggle = ( { onChange }: FormToggleProps ) => {
describe( 'FormToggle', () => {
describe( 'basic rendering', () => {
- it( 'should render a span element with an unchecked checkbox', () => {
- const { container } = render( );
+ it( 'should render a span element with an unchecked checkbox', async () => {
+ const container = createContainer();
+ await render( , { container } );
expect( getInput() ).not.toBeChecked();
expect( container ).toMatchSnapshot();
} );
- it( 'should render a checked checkbox when providing checked prop', () => {
- render( );
+ it( 'should render a checked checkbox when providing checked prop', async () => {
+ await render( );
expect( getInput() ).toBeChecked();
} );
- it( 'should render with an additional className', () => {
- const { container: containerDefault } = render(
-
- );
+ it( 'should render with an additional className', async () => {
+ const containerDefault = createContainer();
+ await render( , {
+ container: containerDefault,
+ } );
- const { container: containerWithClassName } = render(
-
+ const containerWithClassName = createContainer();
+ await render(
+ ,
+ { container: containerWithClassName }
);
// Expect the diff snapshot to be mostly about the className.
@@ -60,16 +71,19 @@ describe( 'FormToggle', () => {
);
} );
- it( 'should render an id prop for the input checkbox', () => {
- const { container: containerDefault } = render(
-
- );
+ it( 'should render an id prop for the input checkbox', async () => {
+ const containerDefault = createContainer();
+ await render( , {
+ container: containerDefault,
+ } );
- const { container: containerWithID } = render(
+ const containerWithID = createContainer();
+ await render(
// Disabled because of our rule restricting literal IDs, preferring
// `withInstanceId`. In this case, it's fine to use literal IDs.
// eslint-disable-next-line no-restricted-syntax
-
+ ,
+ { container: containerWithID }
);
// Expect the diff snapshot to be mostly about the ID.
@@ -82,7 +96,7 @@ describe( 'FormToggle', () => {
const user = userEvent.setup();
const onChange = jest.fn();
- render( );
+ await render( );
const input = getInput();
diff --git a/packages/components/src/form-token-field/test/index.tsx b/packages/components/src/form-token-field/test/index.tsx
index 961214a574c90..9eedcc979a319 100644
--- a/packages/components/src/form-token-field/test/index.tsx
+++ b/packages/components/src/form-token-field/test/index.tsx
@@ -4,12 +4,12 @@
* External dependencies
*/
import {
- render,
screen,
within,
getDefaultNormalizer,
waitFor,
} from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
import type { ComponentProps } from 'react';
@@ -125,7 +125,9 @@ describe( 'FormTokenField', () => {
const onChangeSpy = jest.fn();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'combobox' );
@@ -150,7 +152,9 @@ describe( 'FormTokenField', () => {
const onChangeSpy = jest.fn();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'combobox' );
@@ -166,7 +170,7 @@ describe( 'FormTokenField', () => {
const onChangeSpy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
);
@@ -178,7 +182,7 @@ describe( 'FormTokenField', () => {
expect( onChangeSpy ).toHaveBeenCalledWith( [ 'dragon fruit' ] );
expectTokensToBeInTheDocument( [ 'dragon fruit' ] );
- rerender(
+ await rerender(
{
const onChangeSpy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
);
@@ -222,7 +226,7 @@ describe( 'FormTokenField', () => {
expect( onChangeSpy ).toHaveBeenCalledTimes( 0 );
expectTokensNotToBeInTheDocument( [ 'grapefruit' ] );
- rerender(
+ await rerender(
{
const onChangeSpy = jest.fn();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'combobox' );
@@ -261,7 +267,7 @@ describe( 'FormTokenField', () => {
const onChangeSpy = jest.fn();
- render(
+ await render(
{
const onChangeSpy = jest.fn();
- render(
+ await render(
{
const onChangeSpy = jest.fn();
- render(
+ await render(
{
const onChangeSpy = jest.fn();
- render(
+ await render(
{
const onChangeSpy = jest.fn();
- render(
+ await render(
{
const onChangeSpy = jest.fn();
- render(
+ await render(
{
] );
} );
- it( "should add additional classnames passed via the `className` prop to the input element's 2nd level wrapper", () => {
- render( );
+ it( "should add additional classnames passed via the `className` prop to the input element's 2nd level wrapper", async () => {
+ await render(
+
+ );
const input = screen.getByRole( 'combobox' );
@@ -521,14 +529,14 @@ describe( 'FormTokenField', () => {
);
} );
- it( 'should label the input correctly via the `label` prop', () => {
- const { rerender } = render( );
+ it( 'should label the input correctly via the `label` prop', async () => {
+ const { rerender } = await render( );
expect(
screen.getByRole( 'combobox', { name: 'Add item' } )
).toBeVisible();
- rerender( );
+ await rerender( );
expect(
screen.getByRole( 'combobox', { name: 'Test label' } )
@@ -540,7 +548,7 @@ describe( 'FormTokenField', () => {
const onFocusSpy = jest.fn();
- render( );
+ await render( );
const input = screen.getByRole( 'combobox' );
@@ -562,7 +570,7 @@ describe( 'FormTokenField', () => {
const onInputChangeSpy = jest.fn();
- render(
+ await render(
);
@@ -579,14 +587,14 @@ describe( 'FormTokenField', () => {
);
} );
- it( 'should show extra instructions when the `__experimentalShowHowTo` prop is set to `true`', () => {
+ it( 'should show extra instructions when the `__experimentalShowHowTo` prop is set to `true`', async () => {
const instructionsTokenizeSpace =
'Separate with commas, spaces, or the Enter key.';
const instructionsDefault =
'Separate with commas or the Enter key.';
// The __experimentalShowHowTo prop is `true` by default
- const { rerender } = render( );
+ const { rerender } = await render( );
expect( screen.getByText( instructionsDefault ) ).toBeVisible();
@@ -595,7 +603,7 @@ describe( 'FormTokenField', () => {
screen.getByRole( 'combobox' )
).toHaveAccessibleDescription( instructionsDefault );
- rerender( );
+ await rerender( );
expect(
screen.getByText( instructionsTokenizeSpace )
@@ -606,7 +614,7 @@ describe( 'FormTokenField', () => {
screen.getByRole( 'combobox' )
).toHaveAccessibleDescription( instructionsTokenizeSpace );
- rerender(
+ await rerender(
{
const onChangeSpy = jest.fn();
- render(
+ await render(
{
const onChangeSpy = jest.fn();
- render(
+ await render(
{
} );
describe( 'suggestions', () => {
- it( 'should not render suggestions in its default state', () => {
- render(
+ it( 'should not render suggestions in its default state', async () => {
+ await render(
@@ -705,7 +713,7 @@ describe( 'FormTokenField', () => {
const suggestions = [ 'Cobalt', 'Blue', 'Octane' ];
- render(
+ await render(
<>
{
const suggestions = [ 'Green', 'Emerald', 'Seaweed' ];
- render(
+ await render(
<>
{
const suggestions = [ 'Green', 'Emerald', 'Seaweed' ];
- render(
+ await render(
<>
{
const suggestions = [ 'Green', 'Emerald', 'Seaweed' ];
- render(
+ await render(
<>
{
const suggestions = [ 'White', 'Pearl', 'Alabaster' ];
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'combobox' );
@@ -858,7 +868,9 @@ describe( 'FormTokenField', () => {
const suggestions = [ 'Yellow', 'Canary', 'Gold', 'Blonde' ];
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'combobox' );
@@ -883,7 +895,7 @@ describe( 'FormTokenField', () => {
const suggestions = [ 'Green', 'Emerald', 'Seaweed' ];
- render(
+ await render(
{
'Neon',
];
- render(
+ await render(
{
const suggestions = [ 'Tiger', 'Tangerine', 'Orange' ];
- render(
+ await render(
{
const suggestions = [ 'Black', 'Ash', 'Onyx', 'Ebony' ];
- render(
+ await render(
{
const suggestions = [ 'One', 'Two', 'Three' ];
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'combobox' );
@@ -1110,7 +1124,7 @@ describe( 'FormTokenField', () => {
const suggestions = [ 'One', 'Two', 'Three' ];
- render(
+ await render(
@@ -1139,7 +1153,7 @@ describe( 'FormTokenField', () => {
const suggestions = [ 'One', 'Two', 'Three' ];
- render(
+ await render(
@@ -1168,7 +1182,9 @@ describe( 'FormTokenField', () => {
const suggestions = [ 'Cinnamon', 'Tawny', 'Mocha' ];
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'combobox' );
@@ -1200,7 +1216,7 @@ describe( 'FormTokenField', () => {
'Abnormality',
];
- const { rerender } = render(
+ const { rerender } = await render(
);
@@ -1216,7 +1232,7 @@ describe( 'FormTokenField', () => {
suggestions
);
- rerender(
+ await rerender(
{
it( 'should match the search text against the unescaped values of suggestions with special characters (including spaces)', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
const suggestions = [ 'Aluminum', 'Silver', 'Bronze' ];
- const { rerender } = render( );
+ const { rerender } = await render( );
// Type "sil", but there are no suggestions.
await user.type( screen.getByRole( 'combobox' ), 'sil' );
@@ -1285,7 +1301,9 @@ describe( 'FormTokenField', () => {
// When suggestions change, the "sil" text is matched against the new
// suggestions, which results in the "Silver" suggestion being shown.
- rerender( );
+ await rerender(
+
+ );
expectVisibleSuggestionsToBe( screen.getByRole( 'listbox' ), [
'Silver',
@@ -1297,7 +1315,7 @@ describe( 'FormTokenField', () => {
const suggestions = [ 'Walnut', 'Hazelnut', 'Pecan' ];
- const { rerender } = render(
+ const { rerender } = await render(
);
@@ -1319,7 +1337,7 @@ describe( 'FormTokenField', () => {
} )
).not.toBeInTheDocument();
- rerender(
+ await rerender(
{
const suggestions = [ 'Wood', 'Stone', 'Metal' ];
- render(
+ await render(
(
@@ -1369,7 +1387,7 @@ describe( 'FormTokenField', () => {
const onChangeSpy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
{
expect( onChangeSpy ).not.toHaveBeenCalled();
- rerender(
+ await rerender(
{
const onMouseEnterSpy = jest.fn();
const onMouseLeaveSpy = jest.fn();
- render(
+ await render(
{
expect( onMouseLeaveSpy ).toHaveBeenCalledTimes( 1 );
} );
- it( 'should add an accessible `title` to a token when specified', () => {
- render(
+ it( 'should add an accessible `title` to a token when specified', async () => {
+ await render(
{
it( 'should be still used to filter out duplicate suggestions', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
const onChangeSpy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
{
expect( onChangeSpy ).toHaveBeenCalledTimes( 1 );
expectTokensToBeInTheDocument( [ 'potato', 'carrot' ] );
- rerender(
+ await rerender(
{
const onChangeSpy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
{
'small shirt',
] );
- rerender(
+ await rerender(
{
const suggestions = [ 'Expensive food', 'Free food' ];
- render(
+ await render(
{
const onChangeSpy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
{
expectTokensToBeInTheDocument( [ 'dark blue', 'dark green' ] );
- rerender(
+ await rerender(
{
const suggestions = [ 'Hot coffee', 'Hot tea' ];
- render(
+ await render(
{
} );
it( 'should allow to pass a function that renders tokens with escaped special characters correctly', async () => {
- render(
+ await render(
{
// worth testing, so we can be sure that token values with
// dangerous characters in them don't have these characters carried
// through unescaped to the HTML.
- render(
+ await render(
{
const startsWithCapitalLetter = ( tokenText: string ) =>
/^[A-Z]/.test( tokenText );
- const { rerender } = render(
+ const { rerender } = await render(
);
@@ -1804,7 +1822,7 @@ describe( 'FormTokenField', () => {
expect( onChangeSpy ).toHaveBeenCalledWith( [ 'cherry' ] );
expectTokensToBeInTheDocument( [ 'cherry' ] );
- rerender(
+ await rerender(
{
const onChangeSpy = jest.fn();
- render(
+ await render(
{
] );
} );
- it( "should not affect the number of tokens set via the `value` prop (ie. not caused by tokenizing the user's input)", () => {
- render(
+ it( "should not affect the number of tokens set via the `value` prop (ie. not caused by tokenizing the user's input)", async () => {
+ await render(
{
const onChangeSpy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
);
@@ -1919,7 +1937,7 @@ describe( 'FormTokenField', () => {
expectTokensToBeInTheDocument( [ 'cube', 'sphere', 'cylinder' ] );
// Add a `maxLength` after some tokens have already been added.
- rerender(
+ await rerender(
{
const onChangeSpy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
);
@@ -1958,7 +1976,7 @@ describe( 'FormTokenField', () => {
expect( onChangeSpy ).toHaveBeenCalledWith( [ 'sun' ] );
expectTokensToBeInTheDocument( [ 'sun' ] );
- rerender(
+ await rerender(
);
@@ -1974,7 +1992,7 @@ describe( 'FormTokenField', () => {
const onChangeSpy = jest.fn();
- render(
+ await render(
{
it( 'should announce to assistive technology the addition of a new token', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'combobox' );
@@ -2034,7 +2052,9 @@ describe( 'FormTokenField', () => {
it( 'should announce to assistive technology the addition of a new token with a custom message', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'combobox' );
@@ -2050,7 +2070,9 @@ describe( 'FormTokenField', () => {
it( 'should announce to assistive technology the removal of a token', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'combobox' );
@@ -2065,7 +2087,7 @@ describe( 'FormTokenField', () => {
it( 'should announce to assistive technology the removal of a token with a custom message', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
it( 'should announce to assistive technology the failure of a potential token to pass validation', async () => {
const user = userEvent.setup();
- render(
+ await render(
false }
/>
@@ -2105,7 +2127,7 @@ describe( 'FormTokenField', () => {
it( 'should announce to assistive technology the failure of a potential token to pass validation with a custom message', async () => {
const user = userEvent.setup();
- render(
+ await render(
false }
messages={ customMessages }
@@ -2126,7 +2148,7 @@ describe( 'FormTokenField', () => {
it( 'should announce to assistive technology the result of the matching of the search text against the list of suggestions', async () => {
const user = userEvent.setup();
- render(
+ await render(
@@ -2169,7 +2191,7 @@ describe( 'FormTokenField', () => {
} );
it( 'should update the label for the "delete" button of a token', async () => {
- render(
+ await render(
{
const suggestions = [ 'Pine', 'Pistachio', 'Sage' ];
- render(
+ await render(
<>
Click me
diff --git a/packages/components/src/grid/test/grid.tsx b/packages/components/src/grid/test/grid.tsx
index 150dac578c80a..e9d0f47db9c20 100644
--- a/packages/components/src/grid/test/grid.tsx
+++ b/packages/components/src/grid/test/grid.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
diff --git a/packages/components/src/guide/test/index.tsx b/packages/components/src/guide/test/index.tsx
index eff2886cb038b..febf0da0fc08b 100644
--- a/packages/components/src/guide/test/index.tsx
+++ b/packages/components/src/guide/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, within } from '@testing-library/react';
+import { screen, within } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -15,13 +16,13 @@ const defaultProps = {
};
describe( 'Guide', () => {
- it( 'renders nothing when there are no pages', () => {
- render( );
+ it( 'renders nothing when there are no pages', async () => {
+ await render( );
expect( screen.queryByRole( 'dialog' ) ).not.toBeInTheDocument();
} );
- it( 'renders one page at a time', () => {
- render(
+ it( 'renders one page at a time', async () => {
+ await render(
{
expect( screen.queryByText( 'Page 2' ) ).not.toBeInTheDocument();
} );
- it( 'hides back button and shows forward button on the first page', () => {
- render(
+ it( 'hides back button and shows forward button on the first page', async () => {
+ await render(
{
it( 'shows back button and shows finish button on the last page', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
).toBeVisible();
} );
- it( "doesn't display the page control if there is only one page", () => {
- render(
+ it( "doesn't display the page control if there is only one page", async () => {
+ await render(
Page 1 } ] }
@@ -100,7 +101,7 @@ describe( 'Guide', () => {
it( 'calls onFinish when the finish button is clicked', async () => {
const user = userEvent.setup();
const onFinish = jest.fn();
- render(
+ await render(
{
it( 'calls onFinish when the modal is closed', async () => {
const user = userEvent.setup();
const onFinish = jest.fn();
- render(
+ await render(
{
} );
describe( 'page navigation', () => {
- it( 'renders an empty list when there are no pages', () => {
- render( );
+ it( 'renders an empty list when there are no pages', async () => {
+ await render( );
expect(
screen.queryByRole( 'list', {
name: 'Guide controls',
@@ -143,8 +144,8 @@ describe( 'Guide', () => {
).not.toBeInTheDocument();
} );
- it( 'renders a button for each page', () => {
- render(
+ it( 'renders a button for each page', async () => {
+ await render(
{
it( 'sets the current page when a button is clicked', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
it( 'allows navigating through the pages with the left and right arrows', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
test( 'should render correctly', () => {
- const { container } = render(
+ const container = createContainer();
+ render(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
test( 'should render alignment', () => {
- const { container } = render(
+ const container = createContainer();
+ render(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
test( 'should render spacing', () => {
- const { container } = render(
+ const container = createContainer();
+ render(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
diff --git a/packages/components/src/heading/test/index.tsx b/packages/components/src/heading/test/index.tsx
index 510fb254a4e99..9b8f0023467ec 100644
--- a/packages/components/src/heading/test/index.tsx
+++ b/packages/components/src/heading/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
diff --git a/packages/components/src/higher-order/with-filters/test/index.tsx b/packages/components/src/higher-order/with-filters/test/index.tsx
index fd816df59cfcf..815046f320d13 100644
--- a/packages/components/src/higher-order/with-filters/test/index.tsx
+++ b/packages/components/src/higher-order/with-filters/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, waitFor } from '@testing-library/react';
+import { waitFor } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* WordPress dependencies
@@ -13,6 +14,12 @@ import { addFilter, removeAllFilters, removeFilter } from '@wordpress/hooks';
*/
import withFilters from '..';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
describe( 'withFilters', () => {
const hookName = 'EnhancedComponent';
const MyComponent = () => My component
;
@@ -25,15 +32,16 @@ describe( 'withFilters', () => {
removeAllFilters( hookName, 'test/enhanced-component-spy-2' );
} );
- it( 'should display original component when no filters applied', () => {
+ it( 'should display original component when no filters applied', async () => {
const EnhancedComponent = withFilters( hookName )( MyComponent );
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
expect( container ).toMatchSnapshot();
} );
- it( 'should display a component overridden by the filter', () => {
+ it( 'should display a component overridden by the filter', async () => {
const OverriddenComponent = () => Overridden component
;
addFilter(
'EnhancedComponent',
@@ -42,12 +50,13 @@ describe( 'withFilters', () => {
);
const EnhancedComponent = withFilters( hookName )( MyComponent );
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
expect( container ).toMatchSnapshot();
} );
- it( 'should display two components composed by the filter', () => {
+ it( 'should display two components composed by the filter', async () => {
const ComposedComponent = () => Composed component
;
addFilter(
hookName,
@@ -61,7 +70,8 @@ describe( 'withFilters', () => {
);
const EnhancedComponent = withFilters( hookName )( MyComponent );
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
expect( container ).toMatchSnapshot();
} );
@@ -79,7 +89,8 @@ describe( 'withFilters', () => {
);
const EnhancedComponent = withFilters( hookName )( SpiedComponent );
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
await waitFor( () =>
expect( SpiedComponent ).toHaveBeenCalledTimes( 1 )
@@ -91,7 +102,8 @@ describe( 'withFilters', () => {
const SpiedComponent = jest.fn( () => Spied component
);
const EnhancedComponent = withFilters( hookName )( SpiedComponent );
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
SpiedComponent.mockClear();
@@ -115,7 +127,8 @@ describe( 'withFilters', () => {
const SpiedComponent = jest.fn( () => Spied component
);
const EnhancedComponent = withFilters( hookName )( SpiedComponent );
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
SpiedComponent.mockClear();
@@ -147,7 +160,8 @@ describe( 'withFilters', () => {
it( 'should re-render component twice when new filter added and removed in two different animation frames', async () => {
const SpiedComponent = jest.fn( () => Spied component
);
const EnhancedComponent = withFilters( hookName )( SpiedComponent );
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
SpiedComponent.mockClear();
@@ -183,7 +197,8 @@ describe( 'withFilters', () => {
);
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
SpiedComponent.mockClear();
diff --git a/packages/components/src/higher-order/with-focus-outside/test/index.tsx b/packages/components/src/higher-order/with-focus-outside/test/index.tsx
index a53a1cf11298d..e4a50e4c9dbad 100644
--- a/packages/components/src/higher-order/with-focus-outside/test/index.tsx
+++ b/packages/components/src/higher-order/with-focus-outside/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, waitFor } from '@testing-library/react';
+import { screen, waitFor } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -58,7 +59,7 @@ describe( 'withFocusOutside', () => {
} );
it( 'should not call handler if focus shifts to element within component', async () => {
- render( );
+ await render( );
const input = screen.getByRole( 'textbox' );
const button = screen.getByRole( 'button' );
@@ -72,7 +73,7 @@ describe( 'withFocusOutside', () => {
it( 'should not call handler if focus transitions via click to button', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'textbox' );
const button = screen.getByRole( 'button' );
@@ -84,7 +85,7 @@ describe( 'withFocusOutside', () => {
} );
it( 'should call handler if focus doesn’t shift to element within component', async () => {
- render( );
+ await render( );
const input = screen.getByRole( 'textbox' );
input.focus();
@@ -94,7 +95,7 @@ describe( 'withFocusOutside', () => {
} );
it( 'should not call handler if focus shifts outside the component when the document does not have focus', async () => {
- render( );
+ await render( );
// Force document.hasFocus() to return false to simulate the window/document losing focus
// See https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus.
@@ -108,7 +109,7 @@ describe( 'withFocusOutside', () => {
} );
it( 'should cancel check when unmounting while queued', async () => {
- const { rerender } = render(
+ const { rerender } = await render(
);
@@ -116,7 +117,7 @@ describe( 'withFocusOutside', () => {
input.focus();
input.blur();
- rerender( );
+ await rerender( );
await waitFor( () => expect( onFocusOutside ).not.toHaveBeenCalled() );
} );
diff --git a/packages/components/src/higher-order/with-focus-return/test/index.tsx b/packages/components/src/higher-order/with-focus-return/test/index.tsx
index 74e7b58b8de18..694a6adf3c0cc 100644
--- a/packages/components/src/higher-order/with-focus-return/test/index.tsx
+++ b/packages/components/src/higher-order/with-focus-return/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -45,30 +46,30 @@ describe( 'withFocusReturn()', () => {
activeElement.blur();
} );
- it( 'should render a basic Test component inside the HOC', () => {
- render( );
+ it( 'should render a basic Test component inside the HOC', async () => {
+ await render( );
expect( screen.getByTestId( 'test-element' ) ).toBeVisible();
} );
- it( 'should pass own props through to the wrapped element', () => {
- render( );
+ it( 'should pass own props through to the wrapped element', async () => {
+ await render( );
expect( screen.getByTestId( 'test-element' ) ).toHaveClass(
'test'
);
} );
- it( 'should not pass any withFocusReturn context props through to the wrapped element', () => {
- render( );
+ it( 'should not pass any withFocusReturn context props through to the wrapped element', async () => {
+ await render( );
expect( screen.getByTestId( 'test-element' ) ).not.toHaveAttribute(
'data-focus-history'
);
} );
- it( 'should not switch focus back to the bound focus element', () => {
- const { unmount } = render( , {
+ it( 'should not switch focus back to the bound focus element', async () => {
+ const { unmount } = await render( , {
container: document.body.appendChild(
document.createElement( 'div' )
),
@@ -86,7 +87,7 @@ describe( 'withFocusReturn()', () => {
it( 'should switch focus back when unmounted while having focus', async () => {
const user = userEvent.setup();
- const { unmount } = render( , {
+ const { unmount } = await render( , {
container: document.body.appendChild(
document.createElement( 'div' )
),
diff --git a/packages/components/src/higher-order/with-notices/test/index.tsx b/packages/components/src/higher-order/with-notices/test/index.tsx
index 4b34da40838ee..a8bbe78226714 100644
--- a/packages/components/src/higher-order/with-notices/test/index.tsx
+++ b/packages/components/src/higher-order/with-notices/test/index.tsx
@@ -3,12 +3,12 @@
*/
import {
act,
- render,
fireEvent,
screen,
waitForElementToBeRemoved,
within,
} from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* WordPress dependencies
@@ -26,6 +26,12 @@ import {
import withNotices from '..';
import type { WithNoticeProps } from '../types';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
// Implementation detail of Notice component used to query the dismissal button.
const stockDismissText = 'Close';
@@ -89,9 +95,10 @@ describe( 'withNotices operations', () => {
return ;
};
- it( 'should create notices with createNotice', () => {
+ it( 'should create notices with createNotice', async () => {
const message = 'Aló!';
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
const { getByText } = within( container );
act( () => {
handle.current.createNotice( { content: message } );
@@ -99,9 +106,10 @@ describe( 'withNotices operations', () => {
expect( getByText( message ) ).toBeInTheDocument();
} );
- it( 'should create notices of error status with createErrorNotice', () => {
+ it( 'should create notices of error status with createErrorNotice', async () => {
const message = 'can’t touch this';
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
const { getByText } = within( container );
act( () => {
handle.current.createErrorNotice( message );
@@ -112,7 +120,8 @@ describe( 'withNotices operations', () => {
it( 'should remove a notice with removeNotice', async () => {
const notice = { id: 'so real', content: 'so why can’t I touch it?' };
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
const { getByText } = within( container );
act( () => {
handle.current.createNotice( notice );
@@ -129,7 +138,8 @@ describe( 'withNotices operations', () => {
it( 'should remove all notices with removeAllNotices', async () => {
const messages = [ 'Aló!', 'hu dis?', 'Otis' ];
const notices = noticesFrom( messages );
- const { container } = render( );
+ const container = createContainer();
+ await render( , { container } );
const { getByText } = within( container );
expect(
await waitForElementToBeRemoved( () => {
@@ -144,17 +154,19 @@ describe( 'withNotices operations', () => {
} );
describe( 'withNotices rendering', () => {
- it( 'should display the original component given no notices', () => {
- const { container } = render( );
+ it( 'should display the original component given no notices', async () => {
+ const container = createContainer();
+ await render( , { container } );
expect( container.innerHTML ).toBe( `${ content }
` );
} );
it( 'should display notices with functioning dismissal triggers', async () => {
const messages = [ 'Aló!', 'hu dis?', 'Otis' ];
const notices = noticesFrom( messages );
- const { container } = render(
-
- );
+ const container = createContainer();
+ await render( , {
+ container,
+ } );
const [ buttonRemoveFirst ] =
screen.getAllByLabelText( stockDismissText );
const getRemovalTarget = () =>
diff --git a/packages/components/src/higher-order/with-spoken-messages/test/index.tsx b/packages/components/src/higher-order/with-spoken-messages/test/index.tsx
index b4d37eaa84096..d9b3fe0d839b0 100644
--- a/packages/components/src/higher-order/with-spoken-messages/test/index.tsx
+++ b/packages/components/src/higher-order/with-spoken-messages/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render } from '@testing-library/react';
+
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -9,7 +10,7 @@ import { render } from '@testing-library/react';
import withSpokenMessages from '../';
describe( 'withSpokenMessages', () => {
- it( 'should generate speak and debouncedSpeak props', () => {
+ it( 'should generate speak and debouncedSpeak props', async () => {
const testSpeak = jest.fn();
const testDebouncedSpeak = jest.fn();
const isFunction = ( maybeFunc: any ) =>
@@ -21,7 +22,7 @@ describe( 'withSpokenMessages', () => {
return ;
}
);
- render( );
+ await render( );
// Unrendered element.
expect( testSpeak ).toHaveBeenCalledWith( true );
diff --git a/packages/components/src/icon/test/index.tsx b/packages/components/src/icon/test/index.tsx
index fd9c1650fb3b5..cf179faa6e91f 100644
--- a/packages/components/src/icon/test/index.tsx
+++ b/packages/components/src/icon/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* WordPress dependencies
@@ -22,22 +23,22 @@ describe( 'Icon', () => {
);
- it( 'renders nothing when icon omitted', () => {
- render( );
+ it( 'renders nothing when icon omitted', async () => {
+ await render( );
expect( screen.queryByTestId( testId ) ).not.toBeInTheDocument();
} );
- it( 'renders a dashicon by slug', () => {
- render( );
+ it( 'renders a dashicon by slug', async () => {
+ await render( );
expect( screen.getByTestId( testId ) ).toHaveClass(
'dashicons-format-image'
);
} );
- it( 'renders a dashicon with custom size', () => {
- render(
+ it( 'renders a dashicon with custom size', async () => {
+ await render(
);
@@ -46,34 +47,34 @@ describe( 'Icon', () => {
expect( screen.getByTestId( testId ) ).toHaveStyle( 'font-size:10px' );
} );
- it( 'renders a function', () => {
- render( } /> );
+ it( 'renders a function', async () => {
+ await render( } /> );
expect( screen.getByTestId( testId ) ).toBeVisible();
} );
- it( 'renders an element', () => {
- render( } /> );
+ it( 'renders an element', async () => {
+ await render( } /> );
expect( screen.getByTestId( testId ) ).toBeVisible();
} );
- it( 'renders an svg element', () => {
- render( );
+ it( 'renders an svg element', async () => {
+ await render( );
expect( screen.getByTestId( testId ) ).toBeVisible();
} );
- it( 'renders an svg element with a default width and height of 24', () => {
- render( );
+ it( 'renders an svg element with a default width and height of 24', async () => {
+ await render( );
const icon = screen.getByTestId( testId );
expect( icon ).toHaveAttribute( 'width', '24' );
expect( icon ).toHaveAttribute( 'height', '24' );
} );
- it( 'renders an svg element and override its width and height', () => {
- render(
+ it( 'renders an svg element and override its width and height', async () => {
+ await render(
{
expect( icon ).toHaveAttribute( 'height', '32' );
} );
- it( 'renders an svg element and does not override width and height if already specified', () => {
- render( );
+ it( 'renders an svg element and does not override width and height if already specified', async () => {
+ await render(
+
+ );
const icon = screen.getByTestId( testId );
expect( icon ).toHaveAttribute( 'width', '32' );
expect( icon ).toHaveAttribute( 'height', '32' );
} );
- it( 'renders a component', () => {
+ it( 'renders a component', async () => {
const MyComponent = () => (
);
- render( );
+ await render( );
expect( screen.getByTestId( testId ) ).toHaveClass( className );
} );
diff --git a/packages/components/src/input-control/test/index.js b/packages/components/src/input-control/test/index.js
index ace3086c388c8..8a33c459a2861 100644
--- a/packages/components/src/input-control/test/index.js
+++ b/packages/components/src/input-control/test/index.js
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -22,39 +23,41 @@ describe( 'InputControl', () => {
);
describe( 'Basic rendering', () => {
- it( 'should render', () => {
- render( );
+ it( 'should render', async () => {
+ await render( );
const input = getInput();
expect( input ).toBeTruthy();
} );
- it( 'should render with specified type', () => {
- render( );
+ it( 'should render with specified type', async () => {
+ await render( );
const input = getInput();
expect( input ).toHaveAttribute( 'type', 'number' );
} );
- it( 'should render label', () => {
- render( );
+ it( 'should render label', async () => {
+ await render( );
const input = screen.getByText( 'Hello' );
expect( input ).toBeInTheDocument();
} );
- it( 'should render help text as description', () => {
- render( );
+ it( 'should render help text as description', async () => {
+ await render( );
expect(
screen.getByRole( 'textbox', { description: 'My help text' } )
).toBeInTheDocument();
} );
- it( 'should still render help as aria-describedby when not plain text', () => {
- render( My help text } /> );
+ it( 'should still render help as aria-describedby when not plain text', async () => {
+ await render(
+ My help text } />
+ );
const input = screen.getByRole( 'textbox' );
const help = screen.getByRole( 'link', { name: 'My help text' } );
@@ -70,7 +73,7 @@ describe( 'InputControl', () => {
it( 'should focus its input on mousedown events', async () => {
const user = await userEvent.setup();
const spy = jest.fn();
- render( );
+ await render( );
const target = getInput();
// Hovers the input and presses (without releasing) primary button.
@@ -87,7 +90,7 @@ describe( 'InputControl', () => {
it( 'should update value onChange', async () => {
const user = await userEvent.setup();
const spy = jest.fn();
- render(
+ await render(
spy( v ) } />
);
const input = getInput();
@@ -131,7 +134,7 @@ describe( 'InputControl', () => {
/>
);
};
- render( );
+ await render( );
const input = getInput();
await user.type( input, '2' );
@@ -154,20 +157,22 @@ describe( 'InputControl', () => {
expect( spy ).toHaveBeenCalledTimes( 1 );
} );
- it( 'should change back to initial value prop, if controlled', () => {
+ it( 'should change back to initial value prop, if controlled', async () => {
const spy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
);
const input = getInput();
// Updating the value.
- rerender( );
+ await rerender( );
expect( input ).toHaveValue( 'New' );
// Change it back to the original value.
- rerender( );
+ await rerender(
+
+ );
expect( input ).toHaveValue( 'Original' );
expect( spy ).toHaveBeenCalledTimes( 0 );
@@ -176,7 +181,7 @@ describe( 'InputControl', () => {
it( 'should not commit value until blurred when isPressEnterToChange is true', async () => {
const user = await userEvent.setup();
const spy = jest.fn();
- render(
+ await render(
spy( v ) }
@@ -196,7 +201,7 @@ describe( 'InputControl', () => {
it( 'should commit value when blurred if value is invalid', async () => {
const user = await userEvent.setup();
const spyChange = jest.fn();
- render(
+ await render(
spyChange( v ) }
diff --git a/packages/components/src/isolated-event-container/test/index.tsx b/packages/components/src/isolated-event-container/test/index.tsx
index a914527b937ff..ae3f1e5bd1aad 100644
--- a/packages/components/src/isolated-event-container/test/index.tsx
+++ b/packages/components/src/isolated-event-container/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, within } from '@testing-library/react';
+import { screen, within } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -13,7 +14,7 @@ describe( 'IsolatedEventContainer', () => {
it( 'should pass props to container', async () => {
const user = userEvent.setup();
const clickHandler = jest.fn();
- render(
+ await render(
{
} );
it( 'should render children', async () => {
- render(
+ await render(
Child
@@ -47,7 +48,7 @@ describe( 'IsolatedEventContainer', () => {
const mousedownHandler = jest.fn();
const keydownHandler = jest.fn();
- render(
+ await render(
{
describe( 'ItemGroup component', () => {
- it( 'should render correctly', () => {
- const { container } = render(
+ it( 'should render correctly', async () => {
+ const container = createContainer();
+ await render(
- Code is poetry
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- it( 'should show borders when the isBordered prop is true', () => {
+ it( 'should show borders when the isBordered prop is true', async () => {
// By default, `isBordered` is `false`
- const { container: noBorders } = render(
+ const noBorders = createContainer();
+ await render(
- Code is poetry
-
+ ,
+ { container: noBorders }
);
- const { container: withBorders } = render(
+ const withBorders = createContainer();
+ await render(
- Code is poetry
-
+ ,
+ { container: withBorders }
);
expect( noBorders ).toMatchDiffSnapshot( withBorders );
} );
- it( 'should show rounded corners when the isRounded prop is true', () => {
+ it( 'should show rounded corners when the isRounded prop is true', async () => {
// By default, `isRounded` is `true`
- const { container: roundCorners } = render(
+ const roundCorners = createContainer();
+ await render(
- Code is poetry
-
+ ,
+ { container: roundCorners }
);
- const { container: squaredCorners } = render(
+ const squaredCorners = createContainer();
+ await render(
- Code is poetry
-
+ ,
+ { container: squaredCorners }
);
expect( roundCorners ).toMatchDiffSnapshot( squaredCorners );
} );
- it( 'should render items individually when the isSeparated prop is true', () => {
+ it( 'should render items individually when the isSeparated prop is true', async () => {
// By default, `isSeparated` is `false`
- const { container: groupedItems } = render(
+ const groupedItems = createContainer();
+ await render(
- Code is poetry
-
+ ,
+ { container: groupedItems }
);
- const { container: separatedItems } = render(
+ const separatedItems = createContainer();
+ await render(
- Code is poetry
-
+ ,
+ { container: separatedItems }
);
expect( groupedItems ).toMatchDiffSnapshot( separatedItems );
@@ -76,7 +97,7 @@ describe( 'ItemGroup', () => {
it( 'should render as a `button` if the `onClick` handler is specified', async () => {
const user = userEvent.setup();
const spy = jest.fn();
- render( - Code is poetry
);
+ await render( - Code is poetry
);
const button = screen.getByRole( 'button' );
@@ -87,16 +108,16 @@ describe( 'ItemGroup', () => {
expect( spy ).toHaveBeenCalled();
} );
- it( 'should give priority to the `as` prop even if the `onClick` handler is specified', () => {
+ it( 'should give priority to the `as` prop even if the `onClick` handler is specified', async () => {
const spy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
- Code is poetry
);
expect( screen.getByRole( 'button' ) ).toBeInTheDocument();
expect( screen.queryByRole( 'label' ) ).not.toBeInTheDocument();
- rerender(
+ await rerender(
-
Code is poetry
@@ -106,37 +127,43 @@ describe( 'ItemGroup', () => {
expect( screen.getByRole( 'link' ) ).toBeInTheDocument();
} );
- it( 'should use different amounts of padding depending on the value of the size prop', () => {
+ it( 'should use different amounts of padding depending on the value of the size prop', async () => {
// By default, `size` is `medium`
- const { container: mediumSize } = render(
- - Code is poetry
- );
+ const mediumSize = createContainer();
+ await render( - Code is poetry
, {
+ container: mediumSize,
+ } );
- const { container: largeSize } = render(
- - Code is poetry
- );
+ const largeSize = createContainer();
+ await render( - Code is poetry
, {
+ container: largeSize,
+ } );
expect( mediumSize ).toMatchDiffSnapshot( largeSize );
} );
- it( 'should read the value of the size prop from context when the prop is not defined', () => {
+ it( 'should read the value of the size prop from context when the prop is not defined', async () => {
// By default, `size` is `medium`.
// The instances of `Item` that don't specify a `size` prop, should
// fallback to the value defined on `ItemGroup` via the context.
- const { container: mediumSize } = render(
+ const mediumSize = createContainer();
+ await render(
- Code
- Is
- Poetry
-
+ ,
+ { container: mediumSize }
);
- const { container: largeSize } = render(
+ const largeSize = createContainer();
+ await render(
- Code
- Is
- Poetry
-
+ ,
+ { container: largeSize }
);
expect( mediumSize ).toMatchDiffSnapshot( largeSize );
diff --git a/packages/components/src/keyboard-shortcuts/test/index.tsx b/packages/components/src/keyboard-shortcuts/test/index.tsx
index e7aa78a03210b..8ff378f546093 100644
--- a/packages/components/src/keyboard-shortcuts/test/index.tsx
+++ b/packages/components/src/keyboard-shortcuts/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { createEvent, fireEvent, render, screen } from '@testing-library/react';
+import { createEvent, fireEvent, screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -31,7 +32,7 @@ describe( 'KeyboardShortcuts', () => {
it( 'should capture key events', async () => {
const spy = jest.fn();
- render(
+ await render(
{
expect( spy ).toHaveBeenCalled();
} );
- it( 'should capture key events globally', () => {
+ it( 'should capture key events globally', async () => {
const spy = jest.fn();
- render(
+ await render(
{
expect( spy ).toHaveBeenCalled();
} );
- it( 'should capture key events on specific event', () => {
+ it( 'should capture key events on specific event', async () => {
const spy = jest.fn();
- render(
+ await render(
{
expect( spy.mock.calls[ 0 ][ 0 ].type ).toBe( 'keyup' );
} );
- it( 'should capture key events on children', () => {
+ it( 'should capture key events on children', async () => {
const spy = jest.fn();
- render(
+ await render(
{};
describe( 'MenuItem', () => {
- it( 'should match snapshot when only label provided', () => {
- render( );
+ it( 'should match snapshot when only label provided', async () => {
+ await render( );
expect( screen.getByRole( 'menuitem' ) ).toMatchSnapshot();
} );
- it( 'should match snapshot when all props provided', () => {
- render(
+ it( 'should match snapshot when all props provided', async () => {
+ await render(
);
};
- render( );
+ await render( );
const opener = screen.getByRole( 'button' );
await user.click( opener );
@@ -136,7 +137,7 @@ describe( 'Modal', () => {
>
);
};
- render( );
+ await render( );
await user.click( screen.getByRole( 'button', { name: '💥' } ) );
expect( onRequestClose ).toHaveBeenCalled();
@@ -161,7 +162,7 @@ describe( 'Modal', () => {
>
);
};
- render( );
+ await render( );
await user.click( screen.getByRole( 'button', { name: '🪆' } ) );
expect( onRequestClose ).not.toHaveBeenCalled();
@@ -192,7 +193,7 @@ describe( 'Modal', () => {
>
);
};
- render( );
+ await render( );
await user.keyboard( 'o' );
expect( onRequestClose ).toHaveBeenCalled();
@@ -230,7 +231,9 @@ describe( 'Modal', () => {
>
);
};
- const { container } = render( );
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ await render( , { container } );
// Opens outer modal > hides container.
await user.click( screen.getByRole( 'button', { name: 'Start' } ) );
@@ -255,7 +258,7 @@ describe( 'Modal', () => {
} );
it( 'should render `headerActions` React nodes', async () => {
- render(
+ await render(
A sweet button }
onRequestClose={ noop }
@@ -323,7 +326,7 @@ describe( 'Modal', () => {
it( 'should focus the Modal dialog by default when `focusOnMount` prop is not provided', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const opener = screen.getByRole( 'button', {
name: 'Toggle Modal',
@@ -337,7 +340,7 @@ describe( 'Modal', () => {
it( 'should focus the Modal dialog when `true` passed as value for `focusOnMount` prop', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const opener = screen.getByRole( 'button', {
name: 'Toggle Modal',
@@ -351,7 +354,9 @@ describe( 'Modal', () => {
it( 'should focus the first focusable element in the contents (if found) when `firstContentElement` passed as value for `focusOnMount` prop', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const opener = screen.getByRole( 'button' );
@@ -365,7 +370,7 @@ describe( 'Modal', () => {
it( 'should focus the first element anywhere within the Modal when `firstElement` passed as value for `focusOnMount` prop', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const opener = screen.getByRole( 'button' );
@@ -379,7 +384,7 @@ describe( 'Modal', () => {
it( 'should not move focus when `false` passed as value for `focusOnMount` prop', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const opener = screen.getByRole( 'button', {
name: 'Toggle Modal',
@@ -459,29 +464,29 @@ describe( 'Modal', () => {
it( 'is added and removed when modal opens and closes including when closed due to another modal opening', async () => {
const user = userEvent.setup();
- const { baseElement } = render( );
+ await render( );
await user.keyboard( 'a' ); // Opens modal A.
- expect( baseElement ).toHaveClass( 'is-A-open' );
+ expect( document.body ).toHaveClass( 'is-A-open' );
await user.keyboard( 'b' ); // Opens modal B > closes modal A.
- expect( baseElement ).toHaveClass( 'is-B-open' );
- expect( baseElement ).not.toHaveClass( 'is-A-open' );
+ expect( document.body ).toHaveClass( 'is-B-open' );
+ expect( document.body ).not.toHaveClass( 'is-A-open' );
await user.keyboard( 'b' ); // Closes modal B.
- expect( baseElement ).not.toHaveClass( 'is-B-open' );
+ expect( document.body ).not.toHaveClass( 'is-B-open' );
} );
it( 'is removed even when prop changes while nested modal is open', async () => {
const user = userEvent.setup();
- const { baseElement } = render( );
+ await render( );
await user.keyboard( 'a' ); // Opens modal A.
await user.keyboard( '{Meta>}a{/Meta}' ); // Opens nested modal.
await user.keyboard( 'c' ); // Changes `bodyOpenClassName`.
await user.keyboard( 'a' ); // Closes modal A.
- expect( baseElement ).not.toHaveClass( 'is-A-open' );
+ expect( document.body ).not.toHaveClass( 'is-A-open' );
} );
} );
} );
diff --git a/packages/components/src/navigable-container/test/navigable-menu.tsx b/packages/components/src/navigable-container/test/navigable-menu.tsx
index a5ab228b0c2b2..e7807baed10c6 100644
--- a/packages/components/src/navigable-container/test/navigable-menu.tsx
+++ b/packages/components/src/navigable-container/test/navigable-menu.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -50,7 +51,7 @@ describe( 'NavigableMenu', () => {
const onNavigateSpy = jest.fn();
- render( );
+ await render( );
const focusables = getNavigableMenuFocusables();
@@ -89,7 +90,7 @@ describe( 'NavigableMenu', () => {
const onNavigateSpy = jest.fn();
- render(
+ await render(
{
const onNavigateSpy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
);
@@ -160,7 +161,7 @@ describe( 'NavigableMenu', () => {
expect( onNavigateSpy ).toHaveBeenCalledTimes( 2 );
expect( onNavigateSpy ).toHaveBeenLastCalledWith( 0, firstFocusable );
- rerender(
+ await rerender(
{
const externalWrapperOnKeyDownSpy = jest.fn();
- render(
+ await render(
// Disable reason: this is only for test purposes.
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
@@ -218,7 +219,7 @@ describe( 'NavigableMenu', () => {
it( 'skips its internal logic when the tab key is pressed', async () => {
const user = userEvent.setup();
- render(
+ await render(
<>
Before menu
diff --git a/packages/components/src/navigable-container/test/tababble-container.tsx b/packages/components/src/navigable-container/test/tababble-container.tsx
index eb14842025bec..d3c4d04eb80ca 100644
--- a/packages/components/src/navigable-container/test/tababble-container.tsx
+++ b/packages/components/src/navigable-container/test/tababble-container.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -57,7 +58,9 @@ describe( 'TabbableContainer', () => {
const onNavigateSpy = jest.fn();
- render(
);
+ await render(
+
+ );
const tabbables = getTabbableContainerTabbables();
@@ -90,7 +93,7 @@ describe( 'TabbableContainer', () => {
const onNavigateSpy = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
);
@@ -121,7 +124,7 @@ describe( 'TabbableContainer', () => {
expect( onNavigateSpy ).toHaveBeenCalledTimes( 2 );
expect( onNavigateSpy ).toHaveBeenLastCalledWith( 0, firstTabbable );
- rerender(
+ await rerender(
{
const externalWrapperOnKeyDownSpy = jest.fn();
- render(
+ await render(
// Disable reason: this is only for test purposes.
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
diff --git a/packages/components/src/navigation/test/index.tsx b/packages/components/src/navigation/test/index.tsx
index 20646a6c809bf..a23b0faffce2b 100644
--- a/packages/components/src/navigation/test/index.tsx
+++ b/packages/components/src/navigation/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -172,7 +173,7 @@ const TestNavigationControlled = () => {
describe( 'Navigation', () => {
it( 'should render the panes and active item', async () => {
- render(
);
+ await render(
);
const menuItems = screen.getAllByRole( 'listitem' );
@@ -187,8 +188,8 @@ describe( 'Navigation', () => {
).toHaveTextContent( 'Item 2' );
} );
- it( 'should render anchor links when menu item supplies an href', () => {
- render(
);
+ it( 'should render anchor links when menu item supplies an href', async () => {
+ await render(
);
const linkItem = screen.getByRole( 'link', { name: 'Item 2' } );
@@ -196,8 +197,8 @@ describe( 'Navigation', () => {
expect( linkItem ).toHaveAttribute( 'target', '_blank' );
} );
- it( 'should render a custom component when menu item supplies one', () => {
- render(
);
+ it( 'should render a custom component when menu item supplies one', async () => {
+ await render(
);
expect( screen.getByText( 'customize me' ) ).toBeInTheDocument();
} );
@@ -205,7 +206,7 @@ describe( 'Navigation', () => {
it( 'should set an active category on click', async () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
await user.click( screen.getByRole( 'button', { name: 'Category' } ) );
@@ -216,30 +217,30 @@ describe( 'Navigation', () => {
expect( menuItems[ 1 ] ).toHaveTextContent( 'Child 2' );
} );
- it( 'should render the root title', () => {
- const { rerender } = render(
);
+ it( 'should render the root title', async () => {
+ const { rerender } = await render(
);
expect( screen.queryByRole( 'heading' ) ).not.toBeInTheDocument();
- rerender(
);
+ await rerender(
);
expect( screen.getByRole( 'heading' ) ).toBeInTheDocument();
expect( screen.getByRole( 'heading' ) ).toHaveTextContent( 'Home' );
} );
- it( 'should render badges', () => {
- render(
);
+ it( 'should render badges', async () => {
+ await render(
);
const menuItem = screen.getAllByRole( 'listitem' );
expect( menuItem[ 0 ] ).toHaveTextContent( 'Item 1' + '21' );
} );
- it( 'should render menu titles when items exist', () => {
- const { rerender } = render(
);
+ it( 'should render menu titles when items exist', async () => {
+ const { rerender } = await render(
);
expect( screen.queryByText( 'Menu title' ) ).not.toBeInTheDocument();
- rerender(
);
+ await rerender(
);
expect( screen.getByText( 'Menu title' ) ).toBeInTheDocument();
} );
@@ -247,7 +248,7 @@ describe( 'Navigation', () => {
it( 'should navigate up a level when clicking the back button', async () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
await user.click( screen.getByRole( 'button', { name: 'Category' } ) );
@@ -261,7 +262,7 @@ describe( 'Navigation', () => {
it( 'should navigate correctly when controlled', async () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
// check root menu is shown and item 1 is selected
expect(
diff --git a/packages/components/src/navigator/test/index.tsx b/packages/components/src/navigator/test/index.tsx
index b83bd70d9d744..083c4aa446b14 100644
--- a/packages/components/src/navigator/test/index.tsx
+++ b/packages/components/src/navigator/test/index.tsx
@@ -2,7 +2,8 @@
* External dependencies
*/
import type { ComponentPropsWithoutRef } from 'react';
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -408,38 +409,38 @@ describe( 'Navigator', () => {
window.Element.prototype.getClientRects = originalGetClientRects;
} );
- it( 'should render', () => {
- render(
);
+ it( 'should render', async () => {
+ await render(
);
expect( getScreen( 'home' ) ).toBeInTheDocument();
expect( queryScreen( 'child' ) ).not.toBeInTheDocument();
expect( queryScreen( 'nested' ) ).not.toBeInTheDocument();
} );
- it( 'should show a different screen on the first render depending on the value of `initialPath`', () => {
- render(
);
+ it( 'should show a different screen on the first render depending on the value of `initialPath`', async () => {
+ await render(
);
expect( queryScreen( 'home' ) ).not.toBeInTheDocument();
expect( getScreen( 'child' ) ).toBeInTheDocument();
expect( queryScreen( 'nested' ) ).not.toBeInTheDocument();
} );
- it( 'should ignore changes to `initialPath` after the first render', () => {
- const { rerender } = render(
);
+ it( 'should ignore changes to `initialPath` after the first render', async () => {
+ const { rerender } = await render(
);
expect( getScreen( 'home' ) ).toBeInTheDocument();
expect( queryScreen( 'child' ) ).not.toBeInTheDocument();
expect( queryScreen( 'nested' ) ).not.toBeInTheDocument();
- rerender(
);
+ await rerender(
);
expect( getScreen( 'home' ) ).toBeInTheDocument();
expect( queryScreen( 'child' ) ).not.toBeInTheDocument();
expect( queryScreen( 'nested' ) ).not.toBeInTheDocument();
} );
- it( 'should not rended anything if the `initialPath` does not match any available screen', () => {
- render(
);
+ it( 'should not rended anything if the `initialPath` does not match any available screen', async () => {
+ await render(
);
expect( queryScreen( 'home' ) ).not.toBeInTheDocument();
expect( queryScreen( 'child' ) ).not.toBeInTheDocument();
@@ -451,7 +452,7 @@ describe( 'Navigator', () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
expect( getScreen( 'home' ) ).toBeInTheDocument();
expect( getNavigationButton( 'toChildScreen' ) ).toBeInTheDocument();
@@ -521,7 +522,7 @@ describe( 'Navigator', () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
expect(
getNavigationButton( 'toNonExistingScreen' )
@@ -543,7 +544,7 @@ describe( 'Navigator', () => {
} );
it( 'should escape the value of the `path` prop', async () => {
- render(
);
+ await render(
);
expect( getScreen( 'home' ) ).toBeInTheDocument();
expect(
@@ -564,7 +565,7 @@ describe( 'Navigator', () => {
it( 'should match correctly paths with named arguments', async () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
expect( getScreen( 'home' ) ).toBeInTheDocument();
@@ -594,7 +595,7 @@ describe( 'Navigator', () => {
it( 'should restore focus correctly', async () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
// Navigate to child screen.
await user.click( getNavigationButton( 'toChildScreen' ) );
@@ -643,7 +644,7 @@ describe( 'Navigator', () => {
it( 'should keep focus on an active element inside navigator, while re-rendering', async () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
// Navigate to child screen.
await user.click( getNavigationButton( 'toChildScreen' ) );
@@ -665,7 +666,7 @@ describe( 'Navigator', () => {
it( 'should keep focus on an active element outside navigator, while re-rendering', async () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
// Navigate to child screen.
await user.click( getNavigationButton( 'toChildScreen' ) );
@@ -687,7 +688,7 @@ describe( 'Navigator', () => {
it( 'should restore focus correctly even when the `path` needs to be escaped', async () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
expect( getScreen( 'home' ) ).toBeInTheDocument();
@@ -711,7 +712,7 @@ describe( 'Navigator', () => {
it( 'should restore focus while using goTo and goToParent', async () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
expect( getScreen( 'home' ) ).toBeInTheDocument();
@@ -748,7 +749,7 @@ describe( 'Navigator', () => {
it( 'should skip focus based on location `skipFocus` option', async () => {
const user = userEvent.setup();
- render(
);
+ await render(
);
// Navigate to child screen with skipFocus.
await user.click( getNavigationButton( 'goToWithSkipFocus' ) );
diff --git a/packages/components/src/notice/test/index.tsx b/packages/components/src/notice/test/index.tsx
index b601e8717a1d3..7ad5b5811fe15 100644
--- a/packages/components/src/notice/test/index.tsx
+++ b/packages/components/src/notice/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render } from '@testing-library/react';
+
+import { render } from '@ariakit/test/react';
/**
* WordPress dependencies
@@ -13,6 +14,12 @@ import { speak } from '@wordpress/a11y';
*/
import Notice from '../index';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
jest.mock( '@wordpress/a11y', () => ( { speak: jest.fn() } ) );
const mockedSpeak = jest.mocked( speak );
@@ -25,8 +32,9 @@ describe( 'Notice', () => {
mockedSpeak.mockReset();
} );
- it( 'should match snapshot', () => {
- const { container } = render(
+ it( 'should match snapshot', async () => {
+ const container = createContainer();
+ await render(
{
] }
>
Example
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- it( 'should not have is-dismissible class when isDismissible prop is false', () => {
- const { container } = render(
-
I cannot be dismissed!
+ it( 'should not have is-dismissible class when isDismissible prop is false', async () => {
+ const container = createContainer();
+ await render(
+
I cannot be dismissed!,
+ { container }
);
const wrapper = getNoticeWrapper( container );
@@ -52,33 +63,34 @@ describe( 'Notice', () => {
expect( wrapper ).not.toHaveClass( 'is-dismissible' );
} );
- it( 'should default to info status', () => {
- const { container } = render(
FYI );
+ it( 'should default to info status', async () => {
+ const container = createContainer();
+ await render(
FYI, { container } );
expect( getNoticeWrapper( container ) ).toHaveClass( 'is-info' );
} );
describe( 'useSpokenMessage', () => {
- it( 'should speak the given message', () => {
- render(
FYI );
+ it( 'should speak the given message', async () => {
+ await render(
FYI );
expect( speak ).toHaveBeenCalledWith( 'FYI', 'polite' );
} );
- it( 'should speak the given message by explicit politeness', () => {
- render(
Uh oh! );
+ it( 'should speak the given message by explicit politeness', async () => {
+ await render(
Uh oh! );
expect( speak ).toHaveBeenCalledWith( 'Uh oh!', 'assertive' );
} );
- it( 'should speak the given message by implicit politeness by status', () => {
- render(
Uh oh! );
+ it( 'should speak the given message by implicit politeness by status', async () => {
+ await render(
Uh oh! );
expect( speak ).toHaveBeenCalledWith( 'Uh oh!', 'assertive' );
} );
- it( 'should speak the given message, preferring explicit to implicit politeness', () => {
- render(
+ it( 'should speak the given message, preferring explicit to implicit politeness', async () => {
+ await render(
No need to panic
@@ -90,10 +102,10 @@ describe( 'Notice', () => {
);
} );
- it( 'should coerce a message to a string', () => {
+ it( 'should coerce a message to a string', async () => {
// This test assumes that `@wordpress/a11y` is capable of handling
// markup strings appropriately.
- render(
+ await render(
With emphasis this time.
@@ -105,13 +117,13 @@ describe( 'Notice', () => {
);
} );
- it( 'should not re-speak an effectively equivalent element message', () => {
- const { rerender } = render(
+ it( 'should not re-speak an effectively equivalent element message', async () => {
+ const { rerender } = await render(
With emphasis this time.
);
- rerender(
+ await rerender(
With emphasis this time.
diff --git a/packages/components/src/notice/test/list.tsx b/packages/components/src/notice/test/list.tsx
index 65d896e1eb492..3e81ccca26fc4 100644
--- a/packages/components/src/notice/test/list.tsx
+++ b/packages/components/src/notice/test/list.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -9,8 +10,8 @@ import { render, screen } from '@testing-library/react';
import NoticeList from '../list';
describe( 'NoticeList', () => {
- it( 'should merge className', () => {
- render(
+ it( 'should merge className', async () => {
+ await render(
List of notices
diff --git a/packages/components/src/number-control/test/index.tsx b/packages/components/src/number-control/test/index.tsx
index 3cf3368f1636b..025308b35bf20 100644
--- a/packages/components/src/number-control/test/index.tsx
+++ b/packages/components/src/number-control/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -30,13 +31,13 @@ function StatefulNumberControl( props: NumberControlProps ) {
describe( 'NumberControl', () => {
describe( 'Basic rendering', () => {
- it( 'should render', () => {
- render(
);
+ it( 'should render', async () => {
+ await render(
);
expect( screen.getByRole( 'spinbutton' ) ).toBeVisible();
} );
- it( 'should render custom className', () => {
- render(
);
+ it( 'should render custom className', async () => {
+ await render(
);
expect( screen.getByRole( 'spinbutton' ) ).toBeVisible();
} );
} );
@@ -46,7 +47,7 @@ describe( 'NumberControl', () => {
const user = userEvent.setup();
const spy = jest.fn();
- render(
+ await render(
spy( v ) } />
);
@@ -61,7 +62,7 @@ describe( 'NumberControl', () => {
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render(
+ await render(
{
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render(
+ await render(
{
it( 'should clamp value within range on ENTER keypress', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'spinbutton' );
@@ -165,7 +166,7 @@ describe( 'NumberControl', () => {
it( 'should clamp value within range on blur', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'spinbutton' );
await user.clear( input );
@@ -184,7 +185,7 @@ describe( 'NumberControl', () => {
it( 'should parse non-numeric values to a number on ENTER keypress when required', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'spinbutton' );
await user.clear( input );
@@ -197,7 +198,7 @@ describe( 'NumberControl', () => {
it( 'should parse non-numeric values to empty string on ENTER keypress when not required', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'spinbutton' );
await user.clear( input );
@@ -216,7 +217,7 @@ describe( 'NumberControl', () => {
it( 'should not enforce numerical value for empty string when required is omitted', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'spinbutton' );
await user.clear( input );
@@ -231,7 +232,7 @@ describe( 'NumberControl', () => {
it( 'should enforce numerical value for empty string when required', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'spinbutton' );
await user.clear( input );
@@ -247,7 +248,9 @@ describe( 'NumberControl', () => {
const spy = jest.fn();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -259,7 +262,7 @@ describe( 'NumberControl', () => {
it( 'should increment by step on key UP press', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -271,7 +274,7 @@ describe( 'NumberControl', () => {
it( 'should increment from a negative value', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -283,7 +286,9 @@ describe( 'NumberControl', () => {
it( 'should increment while preserving the decimal value when `step` is “any”', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -295,7 +300,7 @@ describe( 'NumberControl', () => {
it( 'should increment by step multiplied by spinFactor when spinFactor is provided', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
it( 'should increment by shiftStep on key UP + shift press', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -325,7 +332,9 @@ describe( 'NumberControl', () => {
it( 'should increment by shiftStep multiplied by spinFactor on key UP + shift press', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -337,7 +346,9 @@ describe( 'NumberControl', () => {
it( 'should increment by shiftStep while preserving the decimal value when `step` is “any”', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -349,7 +360,9 @@ describe( 'NumberControl', () => {
it( 'should increment by custom shiftStep on key UP + shift press', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -361,7 +374,7 @@ describe( 'NumberControl', () => {
it( 'should increment but be limited by max on shiftStep', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
it( 'should not increment by shiftStep if disabled', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
const user = userEvent.setup();
const spy = jest.fn();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -412,7 +427,7 @@ describe( 'NumberControl', () => {
it( 'should decrement by step on key DOWN press', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -424,7 +439,7 @@ describe( 'NumberControl', () => {
it( 'should decrement from a negative value', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -436,7 +451,9 @@ describe( 'NumberControl', () => {
it( 'should decrement while preserving the decimal value when `step` is “any”', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -448,7 +465,7 @@ describe( 'NumberControl', () => {
it( 'should decrement by step multiplied by spinFactor when spinFactor is provided', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
it( 'should decrement by shiftStep on key DOWN + shift press', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -478,7 +495,9 @@ describe( 'NumberControl', () => {
it( 'should decrement by shiftStep multiplied by spinFactor on key DOWN + shift press', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -490,7 +509,9 @@ describe( 'NumberControl', () => {
it( 'should decrement by shiftStep while preserving the decimal value when `step` is “any”', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -502,7 +523,9 @@ describe( 'NumberControl', () => {
it( 'should decrement by custom shiftStep on key DOWN + shift press', async () => {
const user = userEvent.setup();
- render( );
+ await render(
+
+ );
const input = screen.getByRole( 'spinbutton' );
await user.click( input );
@@ -514,7 +537,7 @@ describe( 'NumberControl', () => {
it( 'should decrement but be limited by min on shiftStep', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
it( 'should not decrement by shiftStep if disabled', async () => {
const user = userEvent.setup();
- render(
+ await render(
{
},
];
- it( 'shows heading label', () => {
- render( );
+ it( 'shows heading label', async () => {
+ await render( );
const paletteLabel = screen.getByRole( 'heading', {
level: 2,
@@ -134,8 +135,8 @@ describe( 'PaletteEdit', () => {
expect( paletteLabel ).toBeVisible();
} );
- it( 'shows heading label with custom heading level', () => {
- render(
+ it( 'shows heading label with custom heading level', async () => {
+ await render(
{
).toBeVisible();
} );
- it( 'shows empty message', () => {
- render(
+ it( 'shows empty message', async () => {
+ await render(
{
} );
it( 'shows an option to remove all colors', async () => {
- render( );
+ await render( );
await click(
screen.getByRole( 'button', {
@@ -181,7 +182,7 @@ describe( 'PaletteEdit', () => {
} );
it( 'shows a reset option when the `canReset` prop is enabled', async () => {
- render(
+ await render(
);
@@ -200,7 +201,7 @@ describe( 'PaletteEdit', () => {
} );
it( 'does not show a reset colors option when `canReset` is disabled', async () => {
- render( );
+ await render( );
await click(
screen.getByRole( 'button', {
@@ -217,7 +218,7 @@ describe( 'PaletteEdit', () => {
it( 'calls the `onChange` with the new color appended', async () => {
const onChange = jest.fn();
- render(
+ await render(
{
it( 'calls the `onChange` with the new gradient appended', async () => {
const onChange = jest.fn();
- render(
+ await render(
{
} );
} );
- it( 'can not add new colors when `canOnlyChangeValues` is enabled', () => {
- render( );
+ it( 'can not add new colors when `canOnlyChangeValues` is enabled', async () => {
+ await render( );
expect(
screen.queryByRole( 'button', {
@@ -286,7 +287,7 @@ describe( 'PaletteEdit', () => {
it( 'can remove a color', async () => {
const onChange = jest.fn();
- render(
+ await render(
{
it( 'can update palette name', async () => {
const onChange = jest.fn();
- render(
+ await render(
{
it( 'can update color palette value', async () => {
const onChange = jest.fn();
- render(
+ await render(
{
it( 'can update gradient palette value', async () => {
const onChange = jest.fn();
- render(
+ await render(
{
describe( 'basic rendering', () => {
- it( 'should render an empty div with the matching className', () => {
- const { container } = render( );
+ it( 'should render an empty div with the matching className', async () => {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ await render( , { container } );
expect( container ).toMatchSnapshot();
} );
- it( 'should render inner content, if opened', () => {
- render(
+ it( 'should render inner content, if opened', async () => {
+ await render(
Content
@@ -27,8 +30,8 @@ describe( 'PanelBody', () => {
expect( screen.getByTestId( 'inner-content' ) ).toBeVisible();
} );
- it( 'should be opened by default', () => {
- render(
+ it( 'should be opened by default', async () => {
+ await render(
Content
@@ -37,8 +40,8 @@ describe( 'PanelBody', () => {
expect( screen.getByTestId( 'inner-content' ) ).toBeVisible();
} );
- it( 'should render as initially opened, if specified', () => {
- render(
+ it( 'should render as initially opened, if specified', async () => {
+ await render(
Content
@@ -47,8 +50,8 @@ describe( 'PanelBody', () => {
expect( screen.getByTestId( 'inner-content' ) ).toBeVisible();
} );
- it( 'should call the children function, if specified', () => {
- const { rerender } = render(
+ it( 'should call the children function, if specified', async () => {
+ const { rerender } = await render(
{ ( { opened } ) => (
@@ -64,7 +67,7 @@ describe( 'PanelBody', () => {
expect( panelContent ).not.toBeVisible();
expect( panelContent ).toHaveAttribute( 'hidden', '' );
- rerender(
+ await rerender(
{ ( { opened } ) => (
@@ -82,8 +85,8 @@ describe( 'PanelBody', () => {
} );
describe( 'toggling', () => {
- it( 'should toggle collapse with opened prop', () => {
- const { rerender } = render(
+ it( 'should toggle collapse with opened prop', async () => {
+ const { rerender } = await render(
Content
@@ -91,7 +94,7 @@ describe( 'PanelBody', () => {
expect( screen.getByTestId( 'inner-content' ) ).toBeVisible();
- rerender(
+ await rerender(
Content
@@ -101,7 +104,7 @@ describe( 'PanelBody', () => {
screen.queryByTestId( 'inner-content' )
).not.toBeInTheDocument();
- rerender(
+ await rerender(
Content
@@ -113,7 +116,7 @@ describe( 'PanelBody', () => {
it( 'should toggle when clicking header', async () => {
const user = userEvent.setup();
- render(
+ await render(
Content
@@ -140,7 +143,7 @@ describe( 'PanelBody', () => {
const user = userEvent.setup();
const mock = jest.fn();
- render(
+ await render(
Content
diff --git a/packages/components/src/panel/test/header.tsx b/packages/components/src/panel/test/header.tsx
index 8f93eb44b074c..672d53ecc2b04 100644
--- a/packages/components/src/panel/test/header.tsx
+++ b/packages/components/src/panel/test/header.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -10,22 +11,24 @@ import PanelHeader from '../header';
describe( 'PanelHeader', () => {
describe( 'basic rendering', () => {
- it( 'should render PanelHeader with empty div inside', () => {
- const { container } = render(
);
+ it( 'should render PanelHeader with empty div inside', async () => {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ await render(
, { container } );
expect( container ).toMatchSnapshot();
} );
- it( 'should render a label matching the text provided in the prop', () => {
- render(
);
+ it( 'should render a label matching the text provided in the prop', async () => {
+ await render(
);
const heading = screen.getByRole( 'heading' );
expect( heading ).toBeVisible();
expect( heading ).toHaveTextContent( 'Some Label' );
} );
- it( 'should render child elements in the panel header body when provided', () => {
- render(
+ it( 'should render child elements in the panel header body when provided', async () => {
+ await render(
Some text
@@ -36,8 +39,8 @@ describe( 'PanelHeader', () => {
expect( term ).toHaveTextContent( 'Some text' );
} );
- it( 'should render both child elements and label when passed in', () => {
- render(
+ it( 'should render both child elements and label when passed in', async () => {
+ await render(
Some text
diff --git a/packages/components/src/panel/test/index.tsx b/packages/components/src/panel/test/index.tsx
index a48c88c36cb50..5ee7be7e7defd 100644
--- a/packages/components/src/panel/test/index.tsx
+++ b/packages/components/src/panel/test/index.tsx
@@ -1,39 +1,48 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
*/
import Panel from '..';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
describe( 'Panel', () => {
describe( 'basic rendering', () => {
- it( 'should render an empty div without any provided props', () => {
- const { container } = render(
);
+ it( 'should render an empty div without any provided props', async () => {
+ const container = createContainer();
+ await render(
, { container } );
expect( container ).toMatchSnapshot();
} );
- it( 'should render a heading when provided text in the header prop', () => {
- render(
);
+ it( 'should render a heading when provided text in the header prop', async () => {
+ await render(
);
const heading = screen.getByRole( 'heading' );
expect( heading ).toBeVisible();
expect( heading ).toHaveTextContent( 'Header Label' );
} );
- it( 'should render an additional className', () => {
- const { container } = render(
-
- );
+ it( 'should render an additional className', async () => {
+ const container = createContainer();
+ await render(
, {
+ container,
+ } );
expect( container ).toMatchSnapshot();
} );
- it( 'should add additional child elements to be rendered in the panel', () => {
- render(
+ it( 'should add additional child elements to be rendered in the panel', async () => {
+ await render(
The Panel
@@ -44,8 +53,8 @@ describe( 'Panel', () => {
expect( term ).toHaveTextContent( 'The Panel' );
} );
- it( 'should render both children and header when provided as props', () => {
- render(
+ it( 'should render both children and header when provided as props', async () => {
+ await render(
The Panel
diff --git a/packages/components/src/panel/test/row.tsx b/packages/components/src/panel/test/row.tsx
index ee052e78dfd51..fa340c7571527 100644
--- a/packages/components/src/panel/test/row.tsx
+++ b/packages/components/src/panel/test/row.tsx
@@ -1,30 +1,39 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
*/
import PanelRow from '../row';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
describe( 'PanelRow', () => {
- it( 'should render with the default class name', () => {
- const { container } = render(
);
+ it( 'should render with the default class name', async () => {
+ const container = createContainer();
+ await render(
, { container } );
expect( container ).toMatchSnapshot();
} );
- it( 'should render with the custom class name', () => {
- const { container } = render(
-
- );
+ it( 'should render with the custom class name', async () => {
+ const container = createContainer();
+ await render(
, {
+ container,
+ } );
expect( container ).toMatchSnapshot();
} );
- it( 'should render child components', () => {
- render(
+ it( 'should render child components', async () => {
+ await render(
Some text
diff --git a/packages/components/src/placeholder/test/index.tsx b/packages/components/src/placeholder/test/index.tsx
index 6d9427af00b4c..b946e6e8f38ed 100644
--- a/packages/components/src/placeholder/test/index.tsx
+++ b/packages/components/src/placeholder/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, within } from '@testing-library/react';
+import { screen, within } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* WordPress dependencies
@@ -56,8 +57,8 @@ describe( 'Placeholder', () => {
} );
describe( 'basic rendering', () => {
- it( 'should by default render label section and content section.', () => {
- render(
);
+ it( 'should by default render label section and content section.', async () => {
+ await render(
);
const placeholder = getPlaceholder();
expect( placeholder ).toHaveClass( 'components-placeholder' );
@@ -89,8 +90,8 @@ describe( 'Placeholder', () => {
expect( placeholderFieldset ).toBeEmptyDOMElement();
} );
- it( 'should render an Icon in the label section', () => {
- render(
);
+ it( 'should render an Icon in the label section', async () => {
+ await render(
);
const placeholder = getPlaceholder();
const icon = within( placeholder ).getByTestId( 'icon' );
@@ -101,9 +102,9 @@ describe( 'Placeholder', () => {
expect( icon ).toBeInTheDocument();
} );
- it( 'should render a label section', () => {
+ it( 'should render a label section', async () => {
const label = 'WordPress';
- render(
);
+ await render(
);
const placeholderLabel = screen.getByText( label );
expect( placeholderLabel ).toHaveClass(
@@ -112,18 +113,18 @@ describe( 'Placeholder', () => {
expect( placeholderLabel ).toBeInTheDocument();
} );
- it( 'should display content from the children property', () => {
+ it( 'should display content from the children property', async () => {
const content = 'Placeholder content';
- render(
{ content } );
+ await render(
{ content } );
const placeholder = screen.getByText( content );
expect( placeholder ).toBeInTheDocument();
expect( placeholder ).toHaveTextContent( content );
} );
- it( 'should display instructions when provided', () => {
+ it( 'should display instructions when provided', async () => {
const instructions = 'Choose an option.';
- render(
+ await render(
Placeholder content
@@ -135,9 +136,9 @@ describe( 'Placeholder', () => {
expect( instructionsContainer ).toBeInTheDocument();
} );
- it( 'should announce instructions to screen readers', () => {
+ it( 'should announce instructions to screen readers', async () => {
const instructions = 'Awesome block placeholder instructions.';
- render(
+ await render(
Placeholder content
@@ -146,16 +147,16 @@ describe( 'Placeholder', () => {
expect( speak ).toHaveBeenCalledWith( instructions );
} );
- it( 'should add an additional className to the top container', () => {
- render(
);
+ it( 'should add an additional className to the top container', async () => {
+ await render(
);
const placeholder = getPlaceholder();
expect( placeholder ).toHaveClass( 'components-placeholder' );
expect( placeholder ).toHaveClass( 'wp-placeholder' );
} );
- it( 'should add additional props to the top level container', () => {
- render(
);
+ it( 'should add additional props to the top level container', async () => {
+ await render(
);
const placeholder = getPlaceholder();
expect( placeholder ).toHaveAttribute( 'data-test', 'test' );
@@ -163,14 +164,14 @@ describe( 'Placeholder', () => {
} );
describe( 'resize aware', () => {
- it( 'should not assign modifier class in first-pass `null` width from `useResizeObserver`', () => {
+ it( 'should not assign modifier class in first-pass `null` width from `useResizeObserver`', async () => {
// @ts-ignore
useResizeObserver.mockReturnValue( [
,
{ width: 480 },
] );
- render(
);
+ await render(
);
const placeholder = getPlaceholder();
expect( placeholder ).toHaveClass( 'is-large' );
@@ -178,14 +179,14 @@ describe( 'Placeholder', () => {
expect( placeholder ).not.toHaveClass( 'is-small' );
} );
- it( 'should assign modifier class', () => {
+ it( 'should assign modifier class', async () => {
// @ts-ignore
useResizeObserver.mockReturnValue( [
,
{ width: null },
] );
- render(
);
+ await render(
);
const placeholder = getPlaceholder();
expect( placeholder ).not.toHaveClass( 'is-large' );
diff --git a/packages/components/src/popover/test/index.tsx b/packages/components/src/popover/test/index.tsx
index f5ee7e96e4c54..118cf8cb9c36a 100644
--- a/packages/components/src/popover/test/index.tsx
+++ b/packages/components/src/popover/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, waitFor, getByText } from '@testing-library/react';
+import { screen, waitFor, getByText } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
import type { CSSProperties } from 'react';
@@ -22,6 +23,12 @@ import Popover from '..';
import type { PopoverProps } from '../types';
import { PopoverInsideIframeRenderedInExternalSlot } from './utils';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
type PositionToPlacementTuple = [
NonNullable< PopoverProps[ 'position' ] >,
NonNullable< PopoverProps[ 'placement' ] >,
@@ -121,7 +128,7 @@ describe( 'Popover', () => {
describe( 'Component', () => {
describe( 'basic behavior', () => {
it( 'should render content', async () => {
- render(
Hello );
+ await render(
Hello );
await waitFor( () =>
expect( screen.getByText( 'Hello' ) ).toBeVisible()
@@ -129,7 +136,7 @@ describe( 'Popover', () => {
} );
it( 'should forward additional props to portaled element', async () => {
- render(
Hello );
+ await render(
Hello );
await waitFor( () =>
expect( screen.getByRole( 'tooltip' ) ).toBeVisible()
@@ -137,10 +144,12 @@ describe( 'Popover', () => {
} );
it( 'should render inline regardless of slot name', async () => {
- const { container } = render(
+ const container = createContainer();
+ await render(
Hello
-
+ ,
+ { container }
);
await waitFor( () =>
@@ -167,7 +176,7 @@ describe( 'Popover', () => {
);
};
- render(
+ await render(
Popover content
);
@@ -181,7 +190,7 @@ describe( 'Popover', () => {
describe( 'focus behavior', () => {
it( 'should focus the popover container when opened', async () => {
- render(
+ await render(
Popover content
@@ -195,7 +204,7 @@ describe( 'Popover', () => {
} );
it( 'should allow focus-on-open behavior to be disabled', async () => {
- render(
+ await render(
Popover content
);
@@ -218,7 +227,7 @@ describe( 'Popover', () => {
props?: Partial< React.ComponentProps< typeof Popover > >
) => {
const user = await userEvent.setup();
- const view = render(
+ await render(
Button 1
Button 2
@@ -233,7 +242,6 @@ describe( 'Popover', () => {
screen.getAllByRole( 'button' );
return {
- ...view,
popover,
firstButton,
secondButton,
@@ -305,18 +313,13 @@ describe( 'Popover', () => {
} );
test( 'when `focusOnMount` is false if `constrainTabbing` is true', async () => {
- const {
- user,
- baseElement,
- firstButton,
- secondButton,
- thirdButton,
- } = await setup( {
- focusOnMount: false,
- constrainTabbing: true,
- } );
+ const { user, firstButton, secondButton, thirdButton } =
+ await setup( {
+ focusOnMount: false,
+ constrainTabbing: true,
+ } );
- expect( baseElement ).toHaveFocus();
+ expect( document.body ).toHaveFocus();
await user.tab();
expect( firstButton ).toHaveFocus();
await user.tab();
@@ -336,13 +339,8 @@ describe( 'Popover', () => {
// which means the default value for `constrainTabbing` is
// 'true', but the provided value should override this.
- const {
- user,
- baseElement,
- firstButton,
- secondButton,
- thirdButton,
- } = await setup( { constrainTabbing: false } );
+ const { user, firstButton, secondButton, thirdButton } =
+ await setup( { constrainTabbing: false } );
await waitFor( () => expect( firstButton ).toHaveFocus() );
await user.tab();
@@ -350,23 +348,18 @@ describe( 'Popover', () => {
await user.tab();
expect( thirdButton ).toHaveFocus();
await user.tab();
- expect( baseElement ).toHaveFocus();
+ expect( document.body ).toHaveFocus();
await user.tab();
expect( firstButton ).toHaveFocus();
await user.tab( { shift: true } );
- expect( baseElement ).toHaveFocus();
+ expect( document.body ).toHaveFocus();
} );
test( 'when `focusOnMount` is false', async () => {
- const {
- user,
- baseElement,
- firstButton,
- secondButton,
- thirdButton,
- } = await setup( { focusOnMount: false } );
+ const { user, firstButton, secondButton, thirdButton } =
+ await setup( { focusOnMount: false } );
- expect( baseElement ).toHaveFocus();
+ expect( document.body ).toHaveFocus();
await user.tab();
expect( firstButton ).toHaveFocus();
await user.tab();
@@ -374,17 +367,16 @@ describe( 'Popover', () => {
await user.tab();
expect( thirdButton ).toHaveFocus();
await user.tab();
- expect( baseElement ).toHaveFocus();
+ expect( document.body ).toHaveFocus();
await user.tab();
expect( firstButton ).toHaveFocus();
await user.tab( { shift: true } );
- expect( baseElement ).toHaveFocus();
+ expect( document.body ).toHaveFocus();
} );
test( 'when `focusOnMount` is true if `constrainTabbing` is false', async () => {
const {
user,
- baseElement,
popover,
firstButton,
secondButton,
@@ -402,24 +394,19 @@ describe( 'Popover', () => {
await user.tab();
expect( thirdButton ).toHaveFocus();
await user.tab();
- expect( baseElement ).toHaveFocus();
+ expect( document.body ).toHaveFocus();
await user.tab();
expect( firstButton ).toHaveFocus();
await user.tab( { shift: true } );
- expect( baseElement ).toHaveFocus();
+ expect( document.body ).toHaveFocus();
} );
test( 'when `focusOnMount` is "firstElement" if `constrainTabbing` is false', async () => {
- const {
- user,
- baseElement,
- firstButton,
- secondButton,
- thirdButton,
- } = await setup( {
- focusOnMount: 'firstElement',
- constrainTabbing: false,
- } );
+ const { user, firstButton, secondButton, thirdButton } =
+ await setup( {
+ focusOnMount: 'firstElement',
+ constrainTabbing: false,
+ } );
await waitFor( () => expect( firstButton ).toHaveFocus() );
await user.tab();
@@ -427,11 +414,11 @@ describe( 'Popover', () => {
await user.tab();
expect( thirdButton ).toHaveFocus();
await user.tab();
- expect( baseElement ).toHaveFocus();
+ expect( document.body ).toHaveFocus();
await user.tab();
expect( firstButton ).toHaveFocus();
await user.tab( { shift: true } );
- expect( baseElement ).toHaveFocus();
+ expect( document.body ).toHaveFocus();
} );
} );
} );
@@ -439,7 +426,7 @@ describe( 'Popover', () => {
describe( 'Slot outside iframe', () => {
it( 'should support cross-document rendering', async () => {
- render(
+ await render(
content
diff --git a/packages/components/src/progress-bar/test/index.tsx b/packages/components/src/progress-bar/test/index.tsx
index c3984318cc618..a28e847f90188 100644
--- a/packages/components/src/progress-bar/test/index.tsx
+++ b/packages/components/src/progress-bar/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -9,9 +10,15 @@ import { render, screen } from '@testing-library/react';
import { ProgressBar } from '..';
import { INDETERMINATE_TRACK_WIDTH } from '../styles';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
describe( 'ProgressBar', () => {
- it( 'should render an indeterminate semantic progress bar element', () => {
- render( );
+ it( 'should render an indeterminate semantic progress bar element', async () => {
+ await render( );
const progressBar = screen.getByRole( 'progressbar' );
@@ -20,8 +27,8 @@ describe( 'ProgressBar', () => {
expect( progressBar ).not.toHaveValue();
} );
- it( 'should render a determinate semantic progress bar element', () => {
- render( );
+ it( 'should render a determinate semantic progress bar element', async () => {
+ await render( );
const progressBar = screen.getByRole( 'progressbar' );
@@ -30,8 +37,9 @@ describe( 'ProgressBar', () => {
expect( progressBar ).toHaveValue( 55 );
} );
- it( 'should use `INDETERMINATE_TRACK_WIDTH`% as track width for indeterminate progress bar', () => {
- const { container } = render( );
+ it( 'should use `INDETERMINATE_TRACK_WIDTH`% as track width for indeterminate progress bar', async () => {
+ const container = createContainer();
+ await render( , { container } );
/**
* We're intentionally not using an accessible selector, because
@@ -48,8 +56,9 @@ describe( 'ProgressBar', () => {
} );
} );
- it( 'should use `value`% as width for determinate progress bar', () => {
- const { container } = render( );
+ it( 'should use `value`% as width for determinate progress bar', async () => {
+ const container = createContainer();
+ await render( , { container } );
/**
* We're intentionally not using an accessible selector, because
@@ -63,12 +72,12 @@ describe( 'ProgressBar', () => {
} );
} );
- it( 'should pass any additional props down to the underlying `progress` element', () => {
+ it( 'should pass any additional props down to the underlying `progress` element', async () => {
const id = 'foo-bar-123';
const ariaLabel = 'in progress...';
const style = { opacity: 1 };
- render(
+ await render(
);
diff --git a/packages/components/src/radio-control/test/index.tsx b/packages/components/src/radio-control/test/index.tsx
index 0be166513a9a4..f9d9fe2770983 100644
--- a/packages/components/src/radio-control/test/index.tsx
+++ b/packages/components/src/radio-control/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -56,9 +57,9 @@ describe.each( [
const [ , Component ] = modeAndComponent;
describe( 'semantics and labelling', () => {
- it( 'should render radio inputs with accessible labels', () => {
+ it( 'should render radio inputs with accessible labels', async () => {
const onChangeSpy = jest.fn();
- render(
+ await render(
);
@@ -71,9 +72,9 @@ describe.each( [
}
} );
- it( 'should not select have a selected value when the `selected` prop does not match any available options', () => {
+ it( 'should not select have a selected value when the `selected` prop does not match any available options', async () => {
const onChangeSpy = jest.fn();
- render(
+ await render(
);
@@ -84,9 +85,9 @@ describe.each( [
).not.toBeInTheDocument();
} );
- it( 'should render mutually exclusive radio inputs', () => {
+ it( 'should render mutually exclusive radio inputs', async () => {
const onChangeSpy = jest.fn();
- render(
+ await render(
{
+ it( 'should use the group help text to describe individual options', async () => {
const onChangeSpy = jest.fn();
- render(
+ await render(
{
+ it( 'should use the option description text to describe individual options', async () => {
const onChangeSpy = jest.fn();
- render(
+ await render(
{
+ it( 'should use both the option description text and the group help text to describe individual options', async () => {
const onChangeSpy = jest.fn();
- render(
+ await render(
{
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render(
+ await render(
);
@@ -192,7 +193,7 @@ describe.each( [
it( 'should select a new value when clicking on the radio label', async () => {
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render(
+ await render(
);
@@ -215,7 +216,7 @@ describe.each( [
it( 'should select a new value when using the arrow keys', async () => {
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render(
+ await render(
);
diff --git a/packages/components/src/range-control/test/index.tsx b/packages/components/src/range-control/test/index.tsx
index d843b615ed007..21bf7f1ae3c6f 100644
--- a/packages/components/src/range-control/test/index.tsx
+++ b/packages/components/src/range-control/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { act, fireEvent, render, screen } from '@testing-library/react';
+import { act, fireEvent, screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -17,10 +18,10 @@ const fireChangeEvent = ( input: HTMLInputElement, value?: number | string ) =>
describe( 'RangeControl', () => {
describe( '#render()', () => {
- it( 'should trigger change callback with numeric value', () => {
+ it( 'should trigger change callback with numeric value', async () => {
const onChange = jest.fn();
- render( );
+ await render( );
const rangeInput = getRangeInput();
const numberInput = getNumberInput();
@@ -35,12 +36,15 @@ describe( 'RangeControl', () => {
expect( onChange ).toHaveBeenCalledWith( 10 );
} );
- it( 'should render with icons', () => {
- const { container } = render(
+ it( 'should render with icons', async () => {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ await render(
+ />,
+ { container }
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
@@ -58,8 +62,8 @@ describe( 'RangeControl', () => {
} );
describe( 'validation', () => {
- it( 'should not apply if new value is lower than minimum', () => {
- render( );
+ it( 'should not apply if new value is lower than minimum', async () => {
+ await render( );
const rangeInput = getRangeInput();
const numberInput = getNumberInput();
@@ -70,8 +74,8 @@ describe( 'RangeControl', () => {
expect( rangeInput.value ).not.toBe( '10' );
} );
- it( 'should not apply if new value is greater than maximum', () => {
- render( );
+ it( 'should not apply if new value is greater than maximum', async () => {
+ await render( );
const rangeInput = getRangeInput();
const numberInput = getNumberInput();
@@ -82,9 +86,9 @@ describe( 'RangeControl', () => {
expect( rangeInput.value ).not.toBe( '21' );
} );
- it( 'should not call onChange if new value is invalid', () => {
+ it( 'should not call onChange if new value is invalid', async () => {
const onChange = jest.fn();
- render(
+ await render(
);
@@ -96,9 +100,9 @@ describe( 'RangeControl', () => {
expect( onChange ).not.toHaveBeenCalled();
} );
- it( 'should keep invalid values in number input until loss of focus', () => {
+ it( 'should keep invalid values in number input until loss of focus', async () => {
const onChange = jest.fn();
- render(
+ await render(
);
@@ -116,8 +120,8 @@ describe( 'RangeControl', () => {
expect( numberInput.value ).toBe( '-1' );
} );
- it( 'should validate when provided a max or min of zero', () => {
- render( );
+ it( 'should validate when provided a max or min of zero', async () => {
+ await render( );
const rangeInput = getRangeInput();
const numberInput = getNumberInput();
@@ -129,8 +133,8 @@ describe( 'RangeControl', () => {
expect( rangeInput.value ).toBe( '0' );
} );
- it( 'should validate when min and max are negative', () => {
- render( );
+ it( 'should validate when min and max are negative', async () => {
+ await render( );
const rangeInput = getRangeInput();
const numberInput = getNumberInput();
@@ -147,9 +151,9 @@ describe( 'RangeControl', () => {
expect( rangeInput.value ).toBe( '-50' );
} );
- it( 'should take into account the step starting from min', () => {
+ it( 'should take into account the step starting from min', async () => {
const onChange = jest.fn();
- render(
+ await render(
{
} );
describe( 'initialPosition / value', () => {
- it( 'should render initial rendered value of 50% of min/max, if no initialPosition or value is defined', () => {
- render( );
+ it( 'should render initial rendered value of 50% of min/max, if no initialPosition or value is defined', async () => {
+ await render( );
const rangeInput = getRangeInput();
expect( rangeInput.value ).toBe( '5' );
} );
- it( 'should render initialPosition if no value is provided', () => {
- render( );
+ it( 'should render initialPosition if no value is provided', async () => {
+ await render( );
const rangeInput = getRangeInput();
expect( rangeInput.value ).toBe( '50' );
} );
- it( 'should render value instead of initialPosition is provided', () => {
- render( );
+ it( 'should render value instead of initialPosition is provided', async () => {
+ await render(
+
+ );
const rangeInput = getRangeInput();
expect( rangeInput.value ).toBe( '10' );
} );
- it( 'should clamp initialPosition between min and max on first render, and on reset', () => {
- render(
+ it( 'should clamp initialPosition between min and max on first render, and on reset', async () => {
+ await render(
{
} );
describe( 'input field', () => {
- it( 'should render an input field by default', () => {
- render( );
+ it( 'should render an input field by default', async () => {
+ await render( );
const numberInput = getNumberInput();
expect( numberInput ).toBeInTheDocument();
} );
- it( 'should not render an input field, if disabled', () => {
- render( );
+ it( 'should not render an input field, if disabled', async () => {
+ await render( );
const numberInput = screen.queryByRole( 'spinbutton' );
expect( numberInput ).not.toBeInTheDocument();
} );
- it( 'should render a zero value into input range and field', () => {
- render( );
+ it( 'should render a zero value into input range and field', async () => {
+ await render( );
const rangeInput = getRangeInput();
const numberInput = getNumberInput();
@@ -256,8 +262,8 @@ describe( 'RangeControl', () => {
expect( numberInput.value ).toBe( '0' );
} );
- it( 'should update both field and range on change', () => {
- render( );
+ it( 'should update both field and range on change', async () => {
+ await render( );
const rangeInput = getRangeInput();
const numberInput = getNumberInput();
@@ -275,8 +281,8 @@ describe( 'RangeControl', () => {
expect( numberInput.value ).toBe( '7' );
} );
- it( 'should reset input values if next value is removed', () => {
- render( );
+ it( 'should reset input values if next value is removed', async () => {
+ await render( );
const rangeInput = getRangeInput();
const numberInput = getNumberInput();
@@ -292,9 +298,9 @@ describe( 'RangeControl', () => {
} );
describe( 'reset', () => {
- it( 'should reset to a custom fallback value, defined by a parent component', () => {
+ it( 'should reset to a custom fallback value, defined by a parent component', async () => {
const spy = jest.fn();
- render(
+ await render(
{
expect( spy ).toHaveBeenCalledWith( 33 );
} );
- it( 'should reset to a 50% of min/max value, of no initialPosition or value is defined', () => {
- render(
+ it( 'should reset to a 50% of min/max value, of no initialPosition or value is defined', async () => {
+ await render(
{
);
};
- it( 'should rerender with new emdeded content if html prop changes', () => {
- render( );
+ it( 'should rerender with new emdeded content if html prop changes', async () => {
+ await render( );
const iframe =
screen.getByTitle< HTMLIFrameElement >( 'SandBox Title' );
diff --git a/packages/components/src/scroll-lock/test/index.tsx b/packages/components/src/scroll-lock/test/index.tsx
index 012251d5f3296..eb7bd3af0bbf5 100644
--- a/packages/components/src/scroll-lock/test/index.tsx
+++ b/packages/components/src/scroll-lock/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render } from '@testing-library/react';
+
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -11,14 +12,14 @@ import ScrollLock from '..';
describe( 'scroll-lock', () => {
const lockingClassName = 'lockscroll';
- it( 'locks when mounted', () => {
+ it( 'locks when mounted', async () => {
expect( document.documentElement ).not.toHaveClass( lockingClassName );
- render( );
+ await render( );
expect( document.documentElement ).toHaveClass( lockingClassName );
} );
- it( 'unlocks when unmounted', () => {
- const { unmount } = render( );
+ it( 'unlocks when unmounted', async () => {
+ const { unmount } = await render( );
expect( document.documentElement ).toHaveClass( lockingClassName );
unmount();
expect( document.documentElement ).not.toHaveClass( lockingClassName );
diff --git a/packages/components/src/scrollable/test/index.tsx b/packages/components/src/scrollable/test/index.tsx
index c35c22982de50..020bec39d81be 100644
--- a/packages/components/src/scrollable/test/index.tsx
+++ b/packages/components/src/scrollable/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
diff --git a/packages/components/src/search-control/test/index.tsx b/packages/components/src/search-control/test/index.tsx
index f130cab1b2a7c..145800dbb1b0f 100644
--- a/packages/components/src/search-control/test/index.tsx
+++ b/packages/components/src/search-control/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import { click, type } from '@ariakit/test';
/**
@@ -42,7 +43,7 @@ describe( 'SearchControl', () => {
it( 'should call onChange with input value when value is changed', async () => {
const onChangeSpy = jest.fn();
- render( );
+ await render( );
const searchInput = screen.getByRole( 'searchbox' );
await type( 'test', searchInput );
@@ -52,7 +53,7 @@ describe( 'SearchControl', () => {
it( 'should render a Reset search button if no onClose function is provided', async () => {
const onChangeSpy = jest.fn();
- render( );
+ await render( );
const searchInput = screen.getByRole( 'searchbox' );
@@ -74,7 +75,7 @@ describe( 'SearchControl', () => {
it( 'should should render a Close button (instead of Reset) when onClose function is provided', async () => {
const onChangeSpy = jest.fn();
const onCloseSpy = jest.fn();
- render(
+ await render(
);
diff --git a/packages/components/src/select-control/test/select-control.tsx b/packages/components/src/select-control/test/select-control.tsx
index 03e3acbf1f732..903ba2f1302df 100644
--- a/packages/components/src/select-control/test/select-control.tsx
+++ b/packages/components/src/select-control/test/select-control.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -10,8 +11,8 @@ import userEvent from '@testing-library/user-event';
import SelectControl from '..';
describe( 'SelectControl', () => {
- it( 'should not render when no options or children are provided', () => {
- render( );
+ it( 'should not render when no options or children are provided', async () => {
+ await render( );
// use `queryByRole` to avoid throwing an error with `getByRole`
expect( screen.queryByRole( 'combobox' ) ).not.toBeInTheDocument();
@@ -21,7 +22,7 @@ describe( 'SelectControl', () => {
const user = await userEvent.setup();
const handleChangeMock = jest.fn();
- render(
+ await render(
@@ -50,7 +51,7 @@ describe( 'SelectControl', () => {
const user = await userEvent.setup();
const handleChangeMock = jest.fn();
- render(
+ await render(
{
- it( 'does not render anything if no shortcut prop is provided', () => {
- const { container } = render( );
+ it( 'does not render anything if no shortcut prop is provided', async () => {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ await render( , { container } );
expect( container ).toBeEmptyDOMElement();
} );
- it( 'renders the shortcut display text when a string is passed as the shortcut', () => {
- render( );
+ it( 'renders the shortcut display text when a string is passed as the shortcut', async () => {
+ await render( );
expect( screen.getByText( 'shortcut text' ) ).toMatchSnapshot();
} );
- it( 'renders the shortcut display text and aria-label when an object is passed as the shortcut with the correct properties', () => {
- render(
+ it( 'renders the shortcut display text and aria-label when an object is passed as the shortcut with the correct properties', async () => {
+ await render(
{
);
} );
- it( 'renders passed className', () => {
- render( );
+ it( 'renders passed className', async () => {
+ await render(
+
+ );
expect( screen.getByText( 'shortcut text' ) ).toMatchSnapshot();
} );
} );
diff --git a/packages/components/src/slot-fill/test/index.js b/packages/components/src/slot-fill/test/index.js
index d269cb4e03641..dfe7f4228093b 100644
--- a/packages/components/src/slot-fill/test/index.js
+++ b/packages/components/src/slot-fill/test/index.js
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, within } from '@testing-library/react';
+import { screen, within } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
diff --git a/packages/components/src/slot-fill/test/slot.js b/packages/components/src/slot-fill/test/slot.js
index 99836a9446352..5dac492a0704b 100644
--- a/packages/components/src/slot-fill/test/slot.js
+++ b/packages/components/src/slot-fill/test/slot.js
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -14,6 +15,11 @@ import { Slot, Fill, Provider } from '../';
*/
import { Component } from '@wordpress/element';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
class Filler extends Component {
constructor() {
super( ...arguments );
@@ -37,34 +43,39 @@ class Filler extends Component {
}
describe( 'Slot', () => {
- it( 'should render empty Fills', () => {
- const { container } = render(
+ it( 'should render empty Fills', async () => {
+ const container = createContainer();
+ await render(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- it( 'should render a string Fill', () => {
- const { container } = render(
+ it( 'should render a string Fill', async () => {
+ const container = createContainer();
+ await render(
content
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- it( 'should render a Fill containing an element', () => {
- const { container } = render(
+ it( 'should render a Fill containing an element', async () => {
+ const container = createContainer();
+ await render(
@@ -72,14 +83,16 @@ describe( 'Slot', () => {
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- it( 'should render a Fill containing an array', () => {
- const { container } = render(
+ it( 'should render a Fill containing an array', async () => {
+ const container = createContainer();
+ await render(
@@ -87,7 +100,8 @@ describe( 'Slot', () => {
{ [ , , 'text' ] }
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
@@ -96,7 +110,7 @@ describe( 'Slot', () => {
it( 'calls the functions passed as the Slot’s fillProps in the Fill', async () => {
const onClose = jest.fn();
const user = userEvent.setup();
- render(
+ await render(
@@ -114,8 +128,9 @@ describe( 'Slot', () => {
expect( onClose ).toHaveBeenCalledTimes( 1 );
} );
- it( 'should render empty Fills without HTML wrapper when render props used', () => {
- const { container } = render(
+ it( 'should render empty Fills without HTML wrapper when render props used', async () => {
+ const container = createContainer();
+ await render(
@@ -127,14 +142,16 @@ describe( 'Slot', () => {
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- it( 'should render a string Fill with HTML wrapper when render props used', () => {
- const { container } = render(
+ it( 'should render a string Fill with HTML wrapper when render props used', async () => {
+ const container = createContainer();
+ await render(
@@ -144,7 +161,8 @@ describe( 'Slot', () => {
content
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
@@ -152,13 +170,15 @@ describe( 'Slot', () => {
it( 'should re-render Slot when not bubbling virtually', async () => {
const user = userEvent.setup();
- const { container } = render(
+ const container = createContainer();
+ await render(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
@@ -168,16 +188,18 @@ describe( 'Slot', () => {
expect( container ).toMatchSnapshot();
} );
- it( 'should render in expected order when fills always mounted', () => {
- const { container, rerender } = render(
+ it( 'should render in expected order when fills always mounted', async () => {
+ const container = createContainer();
+ const { rerender } = await render(
-
+ ,
+ { container }
);
- rerender(
+ await rerender(
@@ -191,7 +213,7 @@ describe( 'Slot', () => {
);
- rerender(
+ await rerender(
@@ -206,7 +228,7 @@ describe( 'Slot', () => {
);
- rerender(
+ await rerender(
@@ -229,16 +251,18 @@ describe( 'Slot', () => {
expect( container ).toMatchSnapshot();
} );
- it( 'should render in expected order when fills unmounted', () => {
- const { container, rerender } = render(
+ it( 'should render in expected order when fills unmounted', async () => {
+ const container = createContainer();
+ const { rerender } = await render(
-
+ ,
+ { container }
);
- rerender(
+ await rerender(
@@ -248,7 +272,7 @@ describe( 'Slot', () => {
);
- rerender(
+ await rerender(
@@ -258,7 +282,7 @@ describe( 'Slot', () => {
);
- rerender(
+ await rerender(
@@ -273,14 +297,16 @@ describe( 'Slot', () => {
expect( container ).toMatchSnapshot();
} );
- it( 'should warn without a Provider', () => {
- const { container } = render(
+ it( 'should warn without a Provider', async () => {
+ const container = createContainer();
+ await render(
<>
- >
+ >,
+ { container }
);
expect( container ).toMatchSnapshot();
@@ -290,8 +316,9 @@ describe( 'Slot', () => {
describe.each( [ false, true ] )(
'bubblesVirtually %p',
( bubblesVirtually ) => {
- it( 'should subsume another slot by the same name', () => {
- const { container, rerender } = render(
+ it( 'should subsume another slot by the same name', async () => {
+ const container = createContainer();
+ const { rerender } = await render(
{
Content
-
+ ,
+ { container }
);
- rerender(
+ await rerender(
{
expect( container ).toMatchSnapshot();
- rerender(
+ await rerender(
@@ -340,8 +368,9 @@ describe( 'Slot', () => {
expect( container ).toMatchSnapshot();
} );
- it( 'should unmount two slots with the same name', () => {
- const { rerender, container } = render(
+ it( 'should unmount two slots with the same name', async () => {
+ const container = createContainer();
+ const { rerender } = await render(
{
/>
Content
-
+ ,
+ { container }
);
- rerender(
+ await rerender(
{
Content
);
- rerender(
+ await rerender(
diff --git a/packages/components/src/snackbar/test/index.tsx b/packages/components/src/snackbar/test/index.tsx
index 6be4e58c92812..9f30d6cb48a34 100644
--- a/packages/components/src/snackbar/test/index.tsx
+++ b/packages/components/src/snackbar/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, within } from '@testing-library/react';
+import { screen, within } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import { click } from '@ariakit/test';
/**
@@ -25,8 +26,8 @@ describe( 'Snackbar', () => {
mockedSpeak.mockReset();
} );
- it( 'should render correctly', () => {
- render( Message );
+ it( 'should render correctly', async () => {
+ await render( Message );
const snackbar = screen.getByTestId( testId );
@@ -34,20 +35,20 @@ describe( 'Snackbar', () => {
expect( snackbar ).toHaveTextContent( 'Message' );
} );
- it( 'should render with an additional className', () => {
- render( Message );
+ it( 'should render with an additional className', async () => {
+ await render( Message );
expect( screen.getByTestId( testId ) ).toHaveClass( 'gutenberg' );
} );
- it( 'should render with an icon', () => {
+ it( 'should render with an icon', async () => {
const testIcon = (
);
- render( Message );
+ await render( Message );
const snackbar = screen.getByTestId( testId );
const icon = within( snackbar ).getByTestId( 'icon' );
@@ -59,7 +60,7 @@ describe( 'Snackbar', () => {
const onRemove = jest.fn();
const onDismiss = jest.fn();
- render(
+ await render(
Message
@@ -83,7 +84,7 @@ describe( 'Snackbar', () => {
const onRemove = jest.fn();
const onDismiss = jest.fn();
- render(
+ await render(
{
const onRemove = jest.fn();
const onDismiss = jest.fn();
- render(
+ await render(
{
} );
describe( 'actions', () => {
- it( 'should render only the first action with a warning when multiple actions are passed', () => {
- render(
+ it( 'should render only the first action with a warning when multiple actions are passed', async () => {
+ await render(
{
expect( action ).toHaveTextContent( 'One' );
} );
- it( 'should be rendered as a link when the `url` prop is set', () => {
- render(
+ it( 'should be rendered as a link when the `url` prop is set', async () => {
+ await render(
{
it( 'should be rendered as a button and call `onClick` when the `onClick` prop is set', async () => {
const onClick = jest.fn();
- render(
+ await render(
Post updated.
@@ -198,8 +199,8 @@ describe( 'Snackbar', () => {
expect( onClick ).toHaveBeenCalledTimes( 1 );
} );
- it( 'should be rendered as a link when the `url` prop and the `onClick` are set', () => {
- render(
+ it( 'should be rendered as a link when the `url` prop and the `onClick` are set', async () => {
+ await render(
{
} );
describe( 'useSpokenMessage', () => {
- it( 'should speak the given message', () => {
- render( FYI );
+ it( 'should speak the given message', async () => {
+ await render( FYI );
expect( speak ).toHaveBeenCalledWith( 'FYI', 'polite' );
} );
- it( 'should speak the given message by explicit politeness', () => {
- render( Uh oh! );
+ it( 'should speak the given message by explicit politeness', async () => {
+ await render( Uh oh! );
expect( speak ).toHaveBeenCalledWith( 'Uh oh!', 'assertive' );
} );
- it( 'should coerce a message to a string', () => {
+ it( 'should coerce a message to a string', async () => {
// This test assumes that `@wordpress/a11y` is capable of handling
// markup strings appropriately.
- render(
+ await render(
With emphasis this time.
@@ -249,13 +250,13 @@ describe( 'Snackbar', () => {
);
} );
- it( 'should not re-speak an effectively equivalent element message', () => {
- const { rerender } = render(
+ it( 'should not re-speak an effectively equivalent element message', async () => {
+ const { rerender } = await render(
With emphasis this time.
);
- rerender(
+ await rerender(
With emphasis this time.
diff --git a/packages/components/src/snackbar/test/list.tsx b/packages/components/src/snackbar/test/list.tsx
index 1b3749d42c61e..c32e4bf47080a 100644
--- a/packages/components/src/snackbar/test/list.tsx
+++ b/packages/components/src/snackbar/test/list.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import { click } from '@ariakit/test';
/**
@@ -17,7 +18,7 @@ describe( 'SnackbarList', () => {
} );
it( 'should get focus after a snackbar is dismissed', async () => {
- render(
+ await render(
{
- test( 'should render correctly', () => {
- const { container } = render( Surface );
+ test( 'should render correctly', async () => {
+ const container = createContainer();
+ await render( Surface, { container } );
expect( container ).toMatchSnapshot();
} );
- test( 'should render variants', () => {
- const view = render( Surface );
- const { container } = render(
- Surface
- );
- expect( container ).toMatchDiffSnapshot( view.container );
+ test( 'should render variants', async () => {
+ const container = createContainer();
+ await render( Surface, { container } );
+ const container2 = createContainer();
+ render( Surface, {
+ container: container2,
+ } );
+ expect( container2 ).toMatchDiffSnapshot( container );
} );
- test( 'should render borderLeft', () => {
- const view = render( Surface );
- const { container } = render( Surface );
- expect( container ).toMatchDiffSnapshot( view.container );
+ test( 'should render borderLeft', async () => {
+ const container = createContainer();
+ await render( Surface, { container } );
+ const container2 = createContainer();
+ render( Surface, {
+ container: container2,
+ } );
+ expect( container2 ).toMatchDiffSnapshot( container );
} );
- test( 'should render borderRight', () => {
- const view = render( Surface );
- const { container } = render( Surface );
- expect( container ).toMatchDiffSnapshot( view.container );
+ test( 'should render borderRight', async () => {
+ const container = createContainer();
+ await render( Surface, { container } );
+ const container2 = createContainer();
+ render( Surface, {
+ container: container2,
+ } );
+ expect( container2 ).toMatchDiffSnapshot( container );
} );
- test( 'should render borderTop', () => {
- const view = render( Surface );
- const { container } = render( Surface );
- expect( container ).toMatchDiffSnapshot( view.container );
+ test( 'should render borderTop', async () => {
+ const container = createContainer();
+ await render( Surface, { container } );
+ const container2 = createContainer();
+ render( Surface, {
+ container: container2,
+ } );
+ expect( container2 ).toMatchDiffSnapshot( container );
} );
- test( 'should render borderBottom', () => {
- const view = render( Surface );
- const { container } = render( Surface );
- expect( container ).toMatchDiffSnapshot( view.container );
+ test( 'should render borderBottom', async () => {
+ const container = createContainer();
+ await render( Surface, { container } );
+ const container2 = createContainer();
+ render( Surface, {
+ container: container2,
+ } );
+ expect( container2 ).toMatchDiffSnapshot( container );
} );
} );
diff --git a/packages/components/src/tab-panel/test/index.tsx b/packages/components/src/tab-panel/test/index.tsx
index 28dd1a81e9e84..f40a28ea86cd0 100644
--- a/packages/components/src/tab-panel/test/index.tsx
+++ b/packages/components/src/tab-panel/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, waitFor } from '@testing-library/react';
+import { screen, waitFor } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import { press, hover, click } from '@ariakit/test';
/**
@@ -64,7 +65,7 @@ describe.each( [
it( 'should use the correct aria attributes', async () => {
const panelRenderFunction = jest.fn();
- render(
+ await render(
);
@@ -102,7 +103,7 @@ describe.each( [
{ ...TABS[ 2 ], icon: media },
];
- render(
+ await render(
{
const panelRenderFunction = jest.fn();
- render(
+ await render(
);
@@ -205,7 +206,7 @@ describe.each( [
it( 'should fall back to first enabled tab if the active tab is removed', async () => {
const mockOnSelect = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
undefined }
@@ -213,7 +214,7 @@ describe.each( [
/>
);
- rerender(
+ await rerender(
undefined }
@@ -226,7 +227,7 @@ describe.each( [
describe( 'With `initialTabName`', () => {
it( 'should render the tab set by initialTabName prop', async () => {
- render(
+ await render(
{
- render(
+ it( 'should not select a tab when `initialTabName` does not match any known tab', async () => {
+ await render(
{
- const { rerender } = render(
+ const { rerender } = await render(
);
- rerender(
+ await rerender(
{
const mockOnSelect = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
{
const mockOnSelect = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
{
const mockOnSelect = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
{
const mockOnSelect = jest.fn();
- render(
+ await render(
{
const mockOnSelect = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
{
@@ -430,7 +431,7 @@ describe.each( [
expect( await getSelectedTab() ).toHaveTextContent( 'Beta' );
// Re-enable all tabs
- rerender(
+ await rerender(
undefined }
@@ -446,7 +447,7 @@ describe.each( [
it( 'should select first enabled tab when the tab associated to `initialTabName` is disabled', async () => {
const mockOnSelect = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
{
if ( tab.name === 'gamma' ) {
@@ -465,7 +466,7 @@ describe.each( [
expect( await getSelectedTab() ).toHaveTextContent( 'Gamma' );
// Re-enable all tabs
- rerender(
+ await rerender(
{
const mockOnSelect = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
undefined }
@@ -493,7 +494,7 @@ describe.each( [
expect( mockOnSelect ).toHaveBeenCalledTimes( 1 );
expect( mockOnSelect ).toHaveBeenLastCalledWith( 'alpha' );
- rerender(
+ await rerender(
{
if ( tab.name === 'alpha' ) {
@@ -510,7 +511,7 @@ describe.each( [
expect( mockOnSelect ).toHaveBeenCalledTimes( 2 );
expect( mockOnSelect ).toHaveBeenLastCalledWith( 'beta' );
- rerender(
+ await rerender(
undefined }
@@ -526,7 +527,7 @@ describe.each( [
it( 'should select the first enabled tab when the tab associated to `initialTabName` becomes disabled while being the active tab', async () => {
const mockOnSelect = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
{
const mockOnSelect = jest.fn();
- render(
+ await render(
undefined }
@@ -649,7 +650,7 @@ describe.each( [
it( 'wraps around the last/first tab when using arrow keys', async () => {
const mockOnSelect = jest.fn();
- render(
+ await render(
undefined }
@@ -686,7 +687,7 @@ describe.each( [
it( 'should not move tab selection when pressing the up/down arrow keys, unless the orientation is changed to `vertical`', async () => {
const mockOnSelect = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
undefined }
@@ -719,7 +720,7 @@ describe.each( [
// Change orientation to `vertical`. When the orientation is vertical,
// left/right arrow keys are replaced by up/down arrow keys.
- rerender(
+ await rerender(
undefined }
@@ -773,7 +774,7 @@ describe.each( [
it( 'should move focus on a tab even if disabled with arrow key, but not with pointer clicks', async () => {
const mockOnSelect = jest.fn();
- render(
+ await render(
{
- render( undefined } /> );
+ await render(
+ undefined } />
+ );
// Tab should initially focus the first tab in the tablist, which
// is Alpha.
@@ -852,7 +855,7 @@ describe.each( [
it( 'switches to manual tab activation when the `selectOnMove` prop is set to `false`', async () => {
const mockOnSelect = jest.fn();
- render(
+ await render(
undefined }
@@ -901,7 +904,9 @@ describe.each( [
describe( 'Tab Attributes', () => {
it( "should apply the tab's `className` to the tab button", async () => {
- render( undefined } /> );
+ await render(
+ undefined } />
+ );
expect(
await screen.findByRole( 'tab', { name: 'Alpha' } )
@@ -917,7 +922,7 @@ describe.each( [
it( 'should apply the `activeClass` to the selected tab', async () => {
const activeClass = 'my-active-tab';
- render(
+ await render(
{};
describe( 'TextControl', () => {
describe( 'When no ID prop is provided', () => {
- it( 'should generate an ID', () => {
- render( );
+ it( 'should generate an ID', async () => {
+ await render( );
expect( screen.getByRole( 'textbox' ) ).toHaveAttribute(
'id',
@@ -21,9 +22,9 @@ describe( 'TextControl', () => {
);
} );
- it( 'should be labelled correctly', () => {
+ it( 'should be labelled correctly', async () => {
const labelValue = 'Test Label';
- render(
+ await render(
);
@@ -36,15 +37,17 @@ describe( 'TextControl', () => {
describe( 'When an ID prop is provided', () => {
const id = 'test-id';
- it( 'should use the passed ID prop if provided', () => {
- render( );
+ it( 'should use the passed ID prop if provided', async () => {
+ await render(
+
+ );
expect( screen.getByRole( 'textbox' ) ).toHaveAttribute( 'id', id );
} );
- it( 'should be labelled correctly', () => {
+ it( 'should be labelled correctly', async () => {
const labelValue = 'Test Label';
- render(
+ await render(
// Use querySelectorAll because the `mark` role is not officially supported
// yet. This should be changed to `getByRole` when it is.
@@ -22,11 +29,13 @@ describe( 'TextHighlight', () => {
it.each( [ [ 'Gutenberg' ], [ 'media' ] ] )(
'should highlight the singular occurance of the text "%s" in the text if it exists',
( highlight ) => {
- const { container } = render(
+ const container = createContainer();
+ render(
+ />,
+ { container }
);
const highlightedEls = getMarks( container );
@@ -39,11 +48,13 @@ describe( 'TextHighlight', () => {
}
);
- it( 'should highlight multiple occurances of the string every time it exists in the text', () => {
+ it( 'should highlight multiple occurances of the string every time it exists in the text', async () => {
const highlight = 'edit';
- const { container } = render(
-
+ const container = createContainer();
+ await render(
+ ,
+ { container }
);
const highlightedEls = getMarks( container );
@@ -55,13 +66,15 @@ describe( 'TextHighlight', () => {
} );
} );
- it( 'should highlight occurances of a string regardless of capitalisation', () => {
+ it( 'should highlight occurances of a string regardless of capitalisation', async () => {
// Note that `The` occurs twice in the default text, once in
// lowercase and once capitalized.
const highlight = 'The';
- const { container } = render(
-
+ const container = createContainer();
+ await render(
+ ,
+ { container }
);
const highlightedEls = getMarks( container );
@@ -77,11 +90,13 @@ describe( 'TextHighlight', () => {
} );
} );
- it( 'should not highlight a string that is not in the text', () => {
+ it( 'should not highlight a string that is not in the text', async () => {
const highlight = 'Antidisestablishmentarianism';
- const { container } = render(
-
+ const container = createContainer();
+ await render(
+ ,
+ { container }
);
const highlightedEls = getMarks( container );
diff --git a/packages/components/src/text/test/index.tsx b/packages/components/src/text/test/index.tsx
index 5fad5582f4d46..4264a27cf02c4 100644
--- a/packages/components/src/text/test/index.tsx
+++ b/packages/components/src/text/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -10,10 +11,17 @@ import { getFontSize } from '../../utils/font-size';
import { COLORS } from '../../utils';
import { Text } from '../';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
describe( 'Text', () => {
describe( 'snapshot tests', () => {
test( 'should render correctly', () => {
- const { container } = render( Lorem ipsum. );
+ const container = createContainer();
+ render( Lorem ipsum., { container } );
expect( container ).toMatchSnapshot();
} );
} );
@@ -142,14 +150,16 @@ describe( 'Text', () => {
} );
test( 'should render highlighted words with highlightCaseSensitive', () => {
- const { container } = render(
+ const container = createContainer();
+ render(
Lorem ipsum.
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
diff --git a/packages/components/src/theme/test/index.tsx b/packages/components/src/theme/test/index.tsx
index 1b32fa1dfa2d6..e8fa527f7d7fb 100644
--- a/packages/components/src/theme/test/index.tsx
+++ b/packages/components/src/theme/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import type { ReactNode } from 'react';
/**
@@ -26,8 +27,8 @@ const MyThemableComponent = ( props: MyThemableComponentProps ) => {
describe( 'Theme', () => {
describe( 'accent color', () => {
- it( 'does not define the accent color (and its variations) as a CSS variable when the `accent` prop is undefined', () => {
- render(
+ it( 'does not define the accent color (and its variations) as a CSS variable when the `accent` prop is undefined', async () => {
+ await render(
Inner
@@ -49,8 +50,8 @@ describe( 'Theme', () => {
} );
} );
- it( 'defines the accent color (and its variations) as a CSS variable', () => {
- render(
+ it( 'defines the accent color (and its variations) as a CSS variable', async () => {
+ await render(
Inner
@@ -66,8 +67,8 @@ describe( 'Theme', () => {
} );
describe( 'background color', () => {
- it( 'does not define the background color (and its dependent colors) as a CSS variable when the `background` prop is undefined', () => {
- render(
+ it( 'does not define the background color (and its dependent colors) as a CSS variable when the `background` prop is undefined', async () => {
+ await render(
Inner
@@ -91,8 +92,8 @@ describe( 'Theme', () => {
} );
} );
- it( 'defines the background color (and its dependent colors) as a CSS variable', () => {
- render(
+ it( 'defines the background color (and its dependent colors) as a CSS variable', async () => {
+ await render(
Inner
diff --git a/packages/components/src/toggle-control/test/index.tsx b/packages/components/src/toggle-control/test/index.tsx
index cc89031d9affa..cefd06283d8f0 100644
--- a/packages/components/src/toggle-control/test/index.tsx
+++ b/packages/components/src/toggle-control/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -9,18 +10,22 @@ import { render, screen } from '@testing-library/react';
import ToggleControl from '..';
describe( 'ToggleControl', () => {
- it( 'should label the toggle', () => {
- render( {} } /> );
+ it( 'should label the toggle', async () => {
+ await render(
+ {} } />
+ );
expect(
screen.getByRole( 'checkbox', { name: 'My toggle' } )
).toBeInTheDocument();
} );
- it( 'triggers change callback with boolean', () => {
+ it( 'triggers change callback with boolean', async () => {
const onChange = jest.fn();
- render( );
+ await render(
+
+ );
screen.getByRole( 'checkbox' ).click();
expect( onChange ).toHaveBeenLastCalledWith( true );
@@ -30,15 +35,17 @@ describe( 'ToggleControl', () => {
} );
describe( 'help', () => {
- it( 'should not give the input a description if no `help` prop', () => {
- render( {} } /> );
+ it( 'should not give the input a description if no `help` prop', async () => {
+ await render(
+ {} } />
+ );
expect(
screen.getByRole( 'checkbox' )
).not.toHaveAccessibleDescription();
} );
- it( "should associate `help` as the input's description", () => {
- render(
+ it( "should associate `help` as the input's description", async () => {
+ await render(
{
await hover( document.body );
await hover( document.body, { clientX: 10, clientY: 10 } );
@@ -95,18 +103,25 @@ describe.each( [
const [ mode, Component ] = modeAndComponent;
describe( 'should render correctly', () => {
- it( 'with text options', () => {
- const { container } = render(
+ it( 'with text options', async () => {
+ const container = createContainer();
+ // TODO: temporarily using the sync version of render until we figure what to do with these snapshots
+ // see: https://github.com/WordPress/gutenberg/pull/64180
+ renderSync(
{ options }
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- it( 'with icons', () => {
- const { container } = render(
+ it( 'with icons', async () => {
+ const container = createContainer();
+ // TODO: temporarily using the sync version of render until we figure what to do with these snapshots
+ // see: https://github.com/WordPress/gutenberg/pull/64180
+ renderSync(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
} );
- it( 'should render with the correct option initially selected when `value` is defined', () => {
- render(
+ it( 'should render with the correct option initially selected when `value` is defined', async () => {
+ await render(
{ options }
@@ -133,8 +149,8 @@ describe.each( [
expect( screen.getByRole( 'radio', { name: 'R' } ) ).not.toBeChecked();
expect( screen.getByRole( 'radio', { name: 'J' } ) ).toBeChecked();
} );
- it( 'should render without a selected option when `value` is `undefined`', () => {
- render(
+ it( 'should render without a selected option when `value` is `undefined`', async () => {
+ await render(
{ options }
);
expect( screen.getByRole( 'radio', { name: 'R' } ) ).not.toBeChecked();
@@ -143,7 +159,7 @@ describe.each( [
it( 'should call onChange with proper value', async () => {
const mockOnChange = jest.fn();
- render(
+ await render(
{
- render(
+ await render(
{ optionsWithTooltip }
@@ -189,7 +205,7 @@ describe.each( [
} );
it( 'should not render tooltip', async () => {
- render(
+ await render(
{ optionsWithTooltip }
@@ -217,7 +233,7 @@ describe.each( [
if ( mode === 'controlled' ) {
it( 'should reset values correctly when default value is undefined', async () => {
- render(
+ await render(
{ options }
@@ -238,7 +254,7 @@ describe.each( [
} );
it( 'should reset values correctly when default value is defined', async () => {
- render(
+ await render(
{ options }
@@ -267,7 +283,7 @@ describe.each( [
'should update correctly when triggered by external updates',
( defaultValueType, defaultValue ) => {
it( `when default value is ${ defaultValueType }`, async () => {
- render(
+ await render(
{
const mockOnChange = jest.fn();
- render(
+ await render(
{
- render(
+ await render(
<>
{ options }
@@ -360,7 +376,7 @@ describe.each( [
it( 'should ignore disabled radio options', async () => {
const mockOnChange = jest.fn();
- render(
+ await render(
{
const mockOnChange = jest.fn();
- render(
+ await render(
{
- render(
+ await render(
{ options }
@@ -474,7 +490,7 @@ describe.each( [
it( 'should ignore disabled options', async () => {
const mockOnChange = jest.fn();
- render(
+ await render(
{
describe( 'basic rendering', () => {
- it( 'should render a toolbar with toolbar buttons', () => {
- render(
+ it( 'should render a toolbar with toolbar buttons', async () => {
+ await render(
@@ -26,8 +27,8 @@ describe( 'Toolbar', () => {
).toBeInTheDocument();
} );
- it( 'should apply the unstyled variant correctly via the `variant` prop', () => {
- render( );
+ it( 'should apply the unstyled variant correctly via the `variant` prop', async () => {
+ await render( );
expect( screen.getByRole( 'toolbar' ) ).toHaveClass(
'is-unstyled'
diff --git a/packages/components/src/toolbar/test/toolbar-group.tsx b/packages/components/src/toolbar/test/toolbar-group.tsx
index 50aa1399c50a6..ba6aa70365182 100644
--- a/packages/components/src/toolbar/test/toolbar-group.tsx
+++ b/packages/components/src/toolbar/test/toolbar-group.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { fireEvent, render, screen } from '@testing-library/react';
+import { fireEvent, screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -13,21 +14,29 @@ import { ToolbarGroup } from '..';
*/
import { wordpress } from '@wordpress/icons';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
describe( 'ToolbarGroup', () => {
describe( 'basic rendering', () => {
- it( 'should render an empty node, when controls are not passed', () => {
- const { container } = render( );
+ it( 'should render an empty node, when controls are not passed', async () => {
+ const container = createContainer();
+ await render( , { container } );
expect( container ).toBeEmptyDOMElement();
} );
- it( 'should render an empty node, when controls are empty', () => {
- const { container } = render( );
+ it( 'should render an empty node, when controls are empty', async () => {
+ const container = createContainer();
+ await render( , { container } );
expect( container ).toBeEmptyDOMElement();
} );
- it( 'should render a list of controls with buttons', () => {
+ it( 'should render a list of controls with buttons', async () => {
const clickHandler = ( event?: React.MouseEvent ) => event;
const controls = [
@@ -39,14 +48,14 @@ describe( 'ToolbarGroup', () => {
},
];
- render( );
+ await render( );
const toolbarButton = screen.getByLabelText( 'WordPress' );
expect( toolbarButton ).toHaveAttribute( 'aria-pressed', 'false' );
expect( toolbarButton ).toHaveAttribute( 'type', 'button' );
} );
- it( 'should render a list of controls with buttons and active control', () => {
+ it( 'should render a list of controls with buttons and active control', async () => {
const clickHandler = ( event?: React.MouseEvent ) => event;
const controls = [
{
@@ -57,14 +66,14 @@ describe( 'ToolbarGroup', () => {
},
];
- render( );
+ await render( );
const toolbarButton = screen.getByLabelText( 'WordPress' );
expect( toolbarButton ).toHaveAttribute( 'aria-pressed', 'true' );
expect( toolbarButton ).toHaveAttribute( 'type', 'button' );
} );
- it( 'should render a nested list of controls with separator between', () => {
+ it( 'should render a nested list of controls with separator between', async () => {
const controls = [
[
// First set.
@@ -82,7 +91,7 @@ describe( 'ToolbarGroup', () => {
],
];
- render( );
+ await render( );
const buttons = screen.getAllByRole( 'button' );
@@ -97,7 +106,7 @@ describe( 'ToolbarGroup', () => {
);
} );
- it( 'should call the clickHandler on click.', () => {
+ it( 'should call the clickHandler on click.', async () => {
const clickHandler = jest.fn();
const controls = [
{
@@ -107,7 +116,7 @@ describe( 'ToolbarGroup', () => {
isActive: true,
},
];
- render( );
+ await render( );
fireEvent.click( screen.getByLabelText( 'WordPress' ) );
expect( clickHandler ).toHaveBeenCalledTimes( 1 );
diff --git a/packages/components/src/tools-panel/test/index.tsx b/packages/components/src/tools-panel/test/index.tsx
index 8d2c4f17a8b17..ab7a5d9f5f38b 100644
--- a/packages/components/src/tools-panel/test/index.tsx
+++ b/packages/components/src/tools-panel/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, within } from '@testing-library/react';
+import { screen, within } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -202,8 +203,8 @@ describe( 'ToolsPanel', () => {
} );
describe( 'basic rendering', () => {
- it( 'should render panel', () => {
- renderPanel();
+ it( 'should render panel', async () => {
+ await renderPanel();
const menuButton = getMenuButton();
const label = screen.getByText( defaultProps.label );
@@ -216,8 +217,8 @@ describe( 'ToolsPanel', () => {
expect( nonToolsPanelItem ).toBeInTheDocument();
} );
- it( 'should render panel item flagged as default control even without value', () => {
- render(
+ it( 'should render panel item flagged as default control even without value', async () => {
+ await render(
Example control
@@ -233,8 +234,8 @@ describe( 'ToolsPanel', () => {
expect( altControl ).toBeInTheDocument();
} );
- it( 'should not render panel menu when there are no panel items', () => {
- render(
+ it( 'should not render panel menu when there are no panel items', async () => {
+ await render(
{ false && (
{
} );
it( 'should render panel menu when at least one panel item', async () => {
- renderPanel();
+ await renderPanel();
const menuButton = await openDropdownMenu();
expect( menuButton ).toBeInTheDocument();
} );
it( 'should render reset all item in menu', async () => {
- renderPanel();
+ await renderPanel();
await openDropdownMenu();
const resetAllItem = await screen.findByRole( 'menuitem' );
@@ -277,7 +278,7 @@ describe( 'ToolsPanel', () => {
} );
it( 'should render panel menu items correctly', async () => {
- renderPanel();
+ await renderPanel();
await openDropdownMenu();
const menuItems = await screen.findAllByRole( 'menuitemcheckbox' );
@@ -287,8 +288,8 @@ describe( 'ToolsPanel', () => {
expect( menuItems[ 1 ] ).not.toBeChecked();
} );
- it( 'should render panel label as header text', () => {
- renderPanel();
+ it( 'should render panel label as header text', async () => {
+ await renderPanel();
const header = screen.getByText( defaultProps.label );
expect( header ).toBeInTheDocument();
@@ -296,8 +297,8 @@ describe( 'ToolsPanel', () => {
} );
describe( 'conditional rendering of panel items', () => {
- it( 'should render panel item when it has a value', () => {
- renderPanel();
+ it( 'should render panel item when it has a value', async () => {
+ await renderPanel();
const exampleControl = screen.getByText( 'Example control' );
const altControl = screen.queryByText( 'Alt control' );
@@ -307,7 +308,7 @@ describe( 'ToolsPanel', () => {
} );
it( 'should render panel item when corresponding menu item is selected', async () => {
- renderPanel();
+ await renderPanel();
await openDropdownMenu();
await selectMenuItem( altControlProps.label );
const control = await screen.findByText( 'Alt control' );
@@ -320,7 +321,7 @@ describe( 'ToolsPanel', () => {
} );
it( 'should prevent optional panel item rendering when toggled off via menu item', async () => {
- renderPanel();
+ await renderPanel();
await openDropdownMenu();
await selectMenuItem( controlProps.label );
const control = screen.queryByText( 'Example control' );
@@ -356,13 +357,15 @@ describe( 'ToolsPanel', () => {
);
};
- const { rerender } = render( );
+ const { rerender } = await render( );
const control = screen.queryByText( 'Optional control' );
expect( control ).not.toBeInTheDocument();
- rerender( );
+ await rerender(
+
+ );
const controlRerendered = screen.getByText( 'Optional control' );
@@ -395,12 +398,12 @@ describe( 'ToolsPanel', () => {
);
};
- const { rerender } = render( );
+ const { rerender } = await render( );
const control = screen.queryByText( 'Optional control' );
expect( control ).not.toBeInTheDocument();
- rerender( );
+ await rerender( );
const controlRerendered = screen.getByText( 'Optional control' );
@@ -408,7 +411,7 @@ describe( 'ToolsPanel', () => {
} );
it( 'should continue to render shown by default item after it is toggled off via menu item', async () => {
- render(
+ await render(
Default control
@@ -432,7 +435,7 @@ describe( 'ToolsPanel', () => {
} );
it( 'should render appropriate menu groups', async () => {
- render(
+ await render(
Default control
@@ -450,8 +453,8 @@ describe( 'ToolsPanel', () => {
expect( menuGroups.length ).toEqual( 2 );
} );
- it( 'should not render contents of items when in placeholder state', () => {
- render(
+ it( 'should not render contents of items when in placeholder state', async () => {
+ await render(
Optional control
@@ -493,7 +496,7 @@ describe( 'ToolsPanel', () => {
);
- const { rerender } = render( );
+ const { rerender } = await render( );
// The linked control should start out as an optional control and is
// not rendered because it does not have a value.
@@ -514,7 +517,7 @@ describe( 'ToolsPanel', () => {
// conditional `isShownByDefault` prop.
altControlValue = true;
- rerender( );
+ await rerender( );
// The linked control should now be a default control and rendered
// despite not having a value.
@@ -567,7 +570,7 @@ describe( 'ToolsPanel', () => {
);
- const { rerender } = render( );
+ const { rerender } = await render( );
// The conditional control should not yet be rendered.
let conditionalItem = screen.queryByText( 'Conditional control' );
@@ -586,7 +589,7 @@ describe( 'ToolsPanel', () => {
// render the new default control into the ToolsPanel.
altControlValue = true;
- rerender( );
+ await rerender( );
// The conditional control should now be rendered and included in
// the panel's menu.
@@ -609,7 +612,7 @@ describe( 'ToolsPanel', () => {
jest.clearAllMocks();
} );
- it( 'should register and deregister items when panelId changes', () => {
+ it( 'should register and deregister items when panelId changes', async () => {
// This test simulates switching block selection, which causes the
// `ToolsPanel` to rerender with a new panelId, necessitating the
// registration and deregistration of appropriate `ToolsPanelItem`
@@ -630,7 +633,7 @@ describe( 'ToolsPanel', () => {
// On the initial render of the panel, the ToolsPanelItem should
// be registered.
- const { rerender } = render( );
+ const { rerender } = await render( );
expect( context.registerPanelItem ).toHaveBeenCalledWith(
expect.objectContaining( {
@@ -647,7 +650,7 @@ describe( 'ToolsPanel', () => {
// Rerender the panel item. Because we have a new panelId, this
// panelItem should NOT be registered, but it SHOULD be
// deregistered.
- rerender( );
+ await rerender( );
// registerPanelItem has still only been called once.
expect( context.registerPanelItem ).toHaveBeenCalledTimes( 1 );
@@ -663,7 +666,7 @@ describe( 'ToolsPanel', () => {
// Rerender the panel and ensure that the panelItem is registered
// again, and it is not de-registered.
- rerender( );
+ await rerender( );
expect( context.registerPanelItem ).toHaveBeenCalledWith(
expect.objectContaining( {
@@ -676,7 +679,7 @@ describe( 'ToolsPanel', () => {
expect( context.deregisterPanelItem ).toHaveBeenCalledTimes( 1 );
} );
- it( 'should register items when ToolsPanel panelId is null', () => {
+ it( 'should register items when ToolsPanel panelId is null', async () => {
// This test simulates when a panel spans multiple block selections.
// Multi-selection means a panel can't have a single id to match
// against the item's. Instead the panel gets an id of `null` and
@@ -697,7 +700,7 @@ describe( 'ToolsPanel', () => {
// On the initial render of the panel, the ToolsPanelItem should
// be registered.
- const { rerender, unmount } = render( );
+ const { rerender, unmount } = await render( );
expect( context.registerPanelItem ).toHaveBeenCalledWith(
expect.objectContaining( {
@@ -709,14 +712,14 @@ describe( 'ToolsPanel', () => {
// Simulate a further block selection being added to the
// multi-selection. The panelId will remain `null` in this case.
- rerender( );
+ await rerender( );
expect( context.registerPanelItem ).toHaveBeenCalledTimes( 1 );
expect( context.deregisterPanelItem ).not.toHaveBeenCalled();
// Simulate a change in panel back to single block selection for
// which the item matches panelId.
context.panelId = '1234';
- rerender( );
+ await rerender( );
expect( context.registerPanelItem ).toHaveBeenCalledTimes( 1 );
expect( context.deregisterPanelItem ).not.toHaveBeenCalled();
@@ -724,14 +727,14 @@ describe( 'ToolsPanel', () => {
// Item should re-register itself after it deregistered as the
// multi-selection occurred.
context.panelId = null;
- rerender( );
+ await rerender( );
expect( context.registerPanelItem ).toHaveBeenCalledTimes( 2 );
expect( context.deregisterPanelItem ).toHaveBeenCalledTimes( 1 );
// Simulate a change in panel e.g. back to a single block selection
// Where the item's panelId is not a match.
context.panelId = '4321';
- rerender( );
+ await rerender( );
// As the item no longer matches the panelId it should not have
// registered again but instead deregistered.
@@ -747,7 +750,7 @@ describe( 'ToolsPanel', () => {
} );
it( 'should call onDeselect callback when menu item is toggled off', async () => {
- renderPanel();
+ await renderPanel();
await openDropdownMenu();
await selectMenuItem( controlProps.label );
@@ -757,7 +760,7 @@ describe( 'ToolsPanel', () => {
} );
it( 'should call onSelect callback when menu item is toggled on', async () => {
- renderPanel();
+ await renderPanel();
await openDropdownMenu();
await selectMenuItem( altControlProps.label );
@@ -767,7 +770,7 @@ describe( 'ToolsPanel', () => {
} );
it( 'should call resetAll callback when its menu item is selected', async () => {
- renderPanel();
+ await renderPanel();
await openDropdownMenu();
await selectMenuItem( 'Reset all' );
@@ -783,7 +786,7 @@ describe( 'ToolsPanel', () => {
// controls does not prevent subsequent individual reset requests.
// i.e. onDeselect callbacks are called correctly after a resetAll.
it( 'should call onDeselect after previous reset all', async () => {
- renderPanel();
+ await renderPanel();
await openDropdownMenu();
await selectMenuItem( 'Reset all' ); // Initial control is displayed by default.
@@ -798,8 +801,8 @@ describe( 'ToolsPanel', () => {
} );
describe( 'grouped panel items within custom components', () => {
- it( 'should render grouped items correctly', () => {
- renderGroupedItemsInPanel();
+ it( 'should render grouped items correctly', async () => {
+ await renderGroupedItemsInPanel();
const defaultItem = screen.getByText( 'Grouped control' );
const altItem = screen.queryByText( 'Alt grouped control' );
@@ -809,7 +812,7 @@ describe( 'ToolsPanel', () => {
} );
it( 'should render grouped items within the menu', async () => {
- renderGroupedItemsInPanel();
+ await renderGroupedItemsInPanel();
await openDropdownMenu();
const defaultItem = screen.getByText( 'Nested Control 1' );
@@ -832,8 +835,8 @@ describe( 'ToolsPanel', () => {
} );
describe( 'wrapped panel items within custom components', () => {
- it( 'should render wrapped items correctly', () => {
- renderWrappedItemInPanel();
+ it( 'should render wrapped items correctly', async () => {
+ await renderWrappedItemInPanel();
const wrappers = screen.getAllByText( 'Wrapper' );
const defaultItem = screen.getByText( 'Wrapped 1' );
@@ -847,7 +850,7 @@ describe( 'ToolsPanel', () => {
} );
it( 'should render wrapped items within the menu', async () => {
- renderWrappedItemInPanel();
+ await renderWrappedItemInPanel();
await openDropdownMenu();
const defaultItem = screen.getByText( 'Nested Control 1' );
@@ -877,7 +880,7 @@ describe( 'ToolsPanel', () => {
it( 'should maintain visual order of controls when toggled on and off', async () => {
// Multiple fills are added to better simulate panel items being
// injected from different locations.
- render(
+ await render(
@@ -948,7 +951,7 @@ describe( 'ToolsPanel', () => {
);
- const { rerender } = render(
+ const { rerender } = await render(
@@ -983,7 +986,7 @@ describe( 'ToolsPanel', () => {
// Close the dropdown menu.
await user.click( menuButton );
- rerender(
+ await rerender(
@@ -1014,7 +1017,7 @@ describe( 'ToolsPanel', () => {
expect( menuItems[ 2 ] ).toHaveTextContent( 'Item 3' );
} );
- it( 'should not trigger callback when fill has not updated yet when panel has', () => {
+ it( 'should not trigger callback when fill has not updated yet when panel has', async () => {
// Fill provided controls can update independently to the panel.
// A `panelId` prop was added to both panels and items
// so it could prevent erroneous registrations and calls to
@@ -1046,7 +1049,7 @@ describe( 'ToolsPanel', () => {
// set its internal state to reflect it was previously selected.
// This later forms part of the condition used to determine if an
// item is being deselected and thus call the onDeselect callback.
- const { rerender } = render(
+ const { rerender } = await render(
Item
@@ -1061,7 +1064,7 @@ describe( 'ToolsPanel', () => {
// Rerender the panel item and ensure that it skips any check
// for deselection given it still belongs to a different panelId.
- rerender(
+ await rerender(
Item
@@ -1100,7 +1103,9 @@ describe( 'ToolsPanel', () => {
);
- const { rerender } = render( );
+ const { rerender } = await render(
+
+ );
await openDropdownMenu();
// Only the item matching the panelId should have been registered
@@ -1118,7 +1123,7 @@ describe( 'ToolsPanel', () => {
// Re-render the panel with different panelID simulating a block
// selection change.
- rerender( );
+ await rerender( );
expect(
screen.queryByRole( 'menuitemcheckbox', {
name: 'Show Alt',
@@ -1156,7 +1161,7 @@ describe( 'ToolsPanel', () => {
};
it( 'should render appropriate labels and descriptions for the dropdown menu where there are default controls', async () => {
- render(
+ await render(
Default control
@@ -1180,7 +1185,7 @@ describe( 'ToolsPanel', () => {
it( 'should render appropriate labels and descriptions for the dropdown menu where there are no default controls', async () => {
// All options are inactive.
- render(
+ await render(
Optional control
@@ -1241,7 +1246,7 @@ describe( 'ToolsPanel', () => {
filters: ResetAllFilter[] | undefined
) => filters?.forEach( ( f ) => f() );
- const { rerender } = render(
+ const { rerender } = await render(
{
resetItem.mockClear();
- rerender(
+ await rerender(
{
} );
describe( 'first and last panel items', () => {
- it( 'should apply first/last classes to appropriate items', () => {
- render(
+ it( 'should apply first/last classes to appropriate items', async () => {
+ await render(
diff --git a/packages/components/src/tooltip/test/index.tsx b/packages/components/src/tooltip/test/index.tsx
index 67922ab1d5ac4..1ca398e34a4f6 100644
--- a/packages/components/src/tooltip/test/index.tsx
+++ b/packages/components/src/tooltip/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen, waitFor } from '@testing-library/react';
+import { screen, waitFor } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import { press, hover, click, sleep } from '@ariakit/test';
/**
@@ -44,7 +45,7 @@ const hoverOutside = async () => {
describe( 'Tooltip', () => {
describe( 'basic behavior', () => {
it( 'should not render the tooltip if multiple children are passed', async () => {
- render(
+ await render(
// @ts-expect-error Tooltip cannot have more than one child element
First button
@@ -65,7 +66,7 @@ describe( 'Tooltip', () => {
} );
it( 'should associate the tooltip text with its anchor via the accessible description when visible', async () => {
- render( );
+ await render( );
// The anchor can not be found by querying for its description,
// since that is present only when the tooltip is visible
@@ -94,8 +95,8 @@ describe( 'Tooltip', () => {
).not.toBeInTheDocument();
} );
- it( 'should not leak Tooltip props to the tooltip anchor', () => {
- render(
+ it( 'should not leak Tooltip props to the tooltip anchor', async () => {
+ await render(
Anchor
@@ -106,7 +107,7 @@ describe( 'Tooltip', () => {
} );
it( 'should add default and custom class names to the tooltip', async () => {
- render( );
+ await render( );
// Hover over the anchor, tooltip should show
await hover(
@@ -125,8 +126,8 @@ describe( 'Tooltip', () => {
} );
describe( 'keyboard focus', () => {
- it( 'should not render the tooltip if there is no focus', () => {
- render( );
+ it( 'should not render the tooltip if there is no focus', async () => {
+ await render( );
expect(
screen.getByRole( 'button', { name: 'Tooltip anchor' } )
@@ -136,7 +137,7 @@ describe( 'Tooltip', () => {
} );
it( 'should show the tooltip when focusing on the tooltip anchor and hide it the anchor loses focus', async () => {
- render(
+ await render(
<>
Focus me
@@ -159,7 +160,7 @@ describe( 'Tooltip', () => {
} );
it( 'should show tooltip when focussing a disabled (but focussable) anchor button', async () => {
- render(
+ await render(
<>
Tooltip anchor
@@ -193,7 +194,7 @@ describe( 'Tooltip', () => {
describe( 'mouse hover', () => {
it( 'should show the tooltip when the tooltip anchor is hovered and hide it when the cursor stops hovering the anchor', async () => {
- render( );
+ await render( );
const anchor = screen.getByRole( 'button', {
name: 'Tooltip anchor',
@@ -211,7 +212,7 @@ describe( 'Tooltip', () => {
} );
it( 'should show tooltip when hovering over a disabled (but focussable) anchor button', async () => {
- render(
+ await render(
<>
Tooltip anchor
@@ -239,7 +240,7 @@ describe( 'Tooltip', () => {
describe( 'mouse click', () => {
it( 'should hide tooltip when the tooltip anchor is clicked', async () => {
- render( );
+ await render( );
const anchor = screen.getByRole( 'button', {
name: 'Tooltip anchor',
@@ -257,7 +258,7 @@ describe( 'Tooltip', () => {
} );
it( 'should not hide tooltip when the tooltip anchor is clicked and the `hideOnClick` prop is `false', async () => {
- render(
+ await render(
<>
Click me
@@ -288,7 +289,7 @@ describe( 'Tooltip', () => {
it( 'should respect custom delay prop when showing tooltip', async () => {
const ADDITIONAL_DELAY = 100;
- render(
+ await render(
{
const onMouseLeaveMock = jest.fn();
const HOVER_OUTSIDE_ANTICIPATION = 200;
- render(
+ await render(
{
describe( 'shortcut', () => {
it( 'should show the shortcut in the tooltip when a string is passed as the shortcut', async () => {
- render( );
+ await render( );
// Hover over the anchor, tooltip should show
await hover(
@@ -392,7 +393,7 @@ describe( 'Tooltip', () => {
} );
it( 'should show the shortcut in the tooltip when an object is passed as the shortcut', async () => {
- render(
+ await render(
{
describe( 'event propagation', () => {
it( 'should close the parent dialog component when pressing the Escape key while the tooltip is visible', async () => {
const onRequestClose = jest.fn();
- render(
+ await render(
Modal content
@@ -460,7 +461,7 @@ describe( 'Tooltip', () => {
describe( 'nested', () => {
it( 'should render the outer tooltip and ignore nested tooltips', async () => {
- render(
+ await render(
@@ -503,8 +504,8 @@ describe( 'Tooltip', () => {
);
} );
- it( 'should not leak Tooltip component classname to the anchor element', () => {
- render(
+ it( 'should not leak Tooltip component classname to the anchor element', async () => {
+ await render(
Anchor
diff --git a/packages/components/src/tree-grid/test/cell.tsx b/packages/components/src/tree-grid/test/cell.tsx
index e0791d6206dc7..14b7e4d114481 100644
--- a/packages/components/src/tree-grid/test/cell.tsx
+++ b/packages/components/src/tree-grid/test/cell.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render } from '@testing-library/react';
+
+import { render } from '@ariakit/test/react';
/**
* WordPress dependencies
@@ -22,8 +23,8 @@ const TestButton = forwardRef(
);
describe( 'TreeGridCell', () => {
- it( 'requires TreeGrid to be declared as a parent component somewhere in the component hierarchy', () => {
- expect( () =>
+ it( 'requires TreeGrid to be declared as a parent component somewhere in the component hierarchy', async () => {
+ await expect( () =>
render(
{ ( props ) => (
@@ -33,12 +34,14 @@ describe( 'TreeGridCell', () => {
) }
)
- ).toThrow();
+ ).rejects.toThrow();
expect( console ).toHaveErrored();
} );
- it( 'uses a child render function to render children', () => {
- const { container } = render(
+ it( 'uses a child render function to render children', async () => {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ await render(
@@ -49,7 +52,8 @@ describe( 'TreeGridCell', () => {
) }
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
diff --git a/packages/components/src/tree-grid/test/index.tsx b/packages/components/src/tree-grid/test/index.tsx
index b4b9d5d370fb4..5f90f0ba0e9c8 100644
--- a/packages/components/src/tree-grid/test/index.tsx
+++ b/packages/components/src/tree-grid/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { fireEvent, render, screen } from '@testing-library/react';
+import { fireEvent, screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* WordPress dependencies
@@ -48,13 +49,16 @@ describe( 'TreeGrid', () => {
} );
describe( 'simple rendering', () => {
- it( 'renders a table, tbody and any child elements', () => {
- const { container } = render(
+ it( 'renders a table, tbody and any child elements', async () => {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ await render(
Test
-
+ ,
+ { container }
);
expect( container.innerHTML ).toMatchSnapshot();
@@ -62,10 +66,10 @@ describe( 'TreeGrid', () => {
} );
describe( 'onExpandRow', () => {
- it( 'should call onExpandRow when pressing Right Arrow on a collapsed row', () => {
+ it( 'should call onExpandRow when pressing Right Arrow on a collapsed row', async () => {
const onExpandRow = jest.fn();
- render(
+ await render(
{
} );
describe( 'onCollapseRow', () => {
- it( 'should call onCollapseRow when pressing Left Arrow on an expanded row', () => {
+ it( 'should call onCollapseRow when pressing Left Arrow on an expanded row', async () => {
const onCollapseRow = jest.fn();
- render(
+ await render(
{
);
- it( 'should call onFocusRow with event, start and end nodes when pressing Down Arrow', () => {
+ it( 'should call onFocusRow with event, start and end nodes when pressing Down Arrow', async () => {
const onFocusRow = jest.fn();
- render( );
+ await render( );
screen.getByText( 'Row 2' ).focus();
@@ -212,9 +216,9 @@ describe( 'TreeGrid', () => {
);
} );
- it( 'should call onFocusRow with event, start and end nodes when pressing End', () => {
+ it( 'should call onFocusRow with event, start and end nodes when pressing End', async () => {
const onFocusRow = jest.fn();
- render( );
+ await render( );
screen.getByText( 'Row 1' ).focus();
@@ -234,9 +238,9 @@ describe( 'TreeGrid', () => {
);
} );
- it( 'should call onFocusRow with event, start and end nodes when pressing Up Arrow', () => {
+ it( 'should call onFocusRow with event, start and end nodes when pressing Up Arrow', async () => {
const onFocusRow = jest.fn();
- render( );
+ await render( );
screen.getByText( 'Row 2' ).focus();
@@ -256,9 +260,9 @@ describe( 'TreeGrid', () => {
);
} );
- it( 'should call onFocusRow with event, start and end nodes when pressing Home', () => {
+ it( 'should call onFocusRow with event, start and end nodes when pressing Home', async () => {
const onFocusRow = jest.fn();
- render( );
+ await render( );
screen.getByText( 'Row 3' ).focus();
@@ -278,9 +282,9 @@ describe( 'TreeGrid', () => {
);
} );
- it( 'should call onFocusRow when shift key is held', () => {
+ it( 'should call onFocusRow when shift key is held', async () => {
const onFocusRow = jest.fn();
- render( );
+ await render( );
screen.getByText( 'Row 2' ).focus();
diff --git a/packages/components/src/tree-grid/test/roving-tab-index-item.tsx b/packages/components/src/tree-grid/test/roving-tab-index-item.tsx
index fe426d1bb5c53..7aa0f8d77c482 100644
--- a/packages/components/src/tree-grid/test/roving-tab-index-item.tsx
+++ b/packages/components/src/tree-grid/test/roving-tab-index-item.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render } from '@testing-library/react';
+
+import { render } from '@ariakit/test/react';
/**
* WordPress dependencies
@@ -14,6 +15,12 @@ import { forwardRef } from '@wordpress/element';
import RovingTabIndex from '../roving-tab-index';
import RovingTabIndexItem from '../roving-tab-index-item';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
const TestButton = forwardRef(
(
{ ...props }: React.ComponentPropsWithoutRef< 'button' >,
@@ -22,37 +29,42 @@ const TestButton = forwardRef(
);
describe( 'RovingTabIndexItem', () => {
- it( 'requires RovingTabIndex to be declared as a parent component somewhere in the component hierarchy', () => {
- expect( () =>
+ it( 'requires RovingTabIndex to be declared as a parent component somewhere in the component hierarchy', async () => {
+ await expect( () =>
render( )
- ).toThrow();
+ ).rejects.toThrow();
expect( console ).toHaveErrored();
} );
- it( 'allows another component to be specified as the rendered component using the `as` prop', () => {
- const { container } = render(
+ it( 'allows another component to be specified as the rendered component using the `as` prop', async () => {
+ const container = createContainer();
+ await render(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- it( 'forwards props to the `as` component', () => {
- const { container } = render(
+ it( 'forwards props to the `as` component', async () => {
+ const container = createContainer();
+ await render(
Click Me!
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- it( 'allows children to be declared using a child render function as an alternative to `as`', () => {
- const { container } = render(
+ it( 'allows children to be declared using a child render function as an alternative to `as`', async () => {
+ const container = createContainer();
+ await render(
{ ( props: React.ComponentProps< typeof TestButton > ) => (
@@ -61,7 +73,8 @@ describe( 'RovingTabIndexItem', () => {
) }
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
diff --git a/packages/components/src/tree-grid/test/roving-tab-index.tsx b/packages/components/src/tree-grid/test/roving-tab-index.tsx
index f346de4f0a1a3..8a291453a6bce 100644
--- a/packages/components/src/tree-grid/test/roving-tab-index.tsx
+++ b/packages/components/src/tree-grid/test/roving-tab-index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render } from '@testing-library/react';
+
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -9,11 +10,14 @@ import { render } from '@testing-library/react';
import RovingTabIndex from '../roving-tab-index';
describe( 'RovingTabIndex', () => {
- it( 'does not render any elements other than its children', () => {
- const { container } = render(
+ it( 'does not render any elements other than its children', async () => {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ await render(
child element
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
diff --git a/packages/components/src/tree-grid/test/row.tsx b/packages/components/src/tree-grid/test/row.tsx
index d0cdf2c9b7aee..b9a68fe38b943 100644
--- a/packages/components/src/tree-grid/test/row.tsx
+++ b/packages/components/src/tree-grid/test/row.tsx
@@ -1,30 +1,40 @@
/**
* External dependencies
*/
-import { render } from '@testing-library/react';
+
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
*/
import TreeGridRow from '../row';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
describe( 'TreeGridRow', () => {
- it( 'renders a tr with support for level, positionInSet and setSize props', () => {
- const { container } = render(
+ it( 'renders a tr with support for level, positionInSet and setSize props', async () => {
+ const container = createContainer();
+ await render(
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- it( 'forwards other props to the rendered tr element', () => {
- const { container } = render(
+ it( 'forwards other props to the rendered tr element', async () => {
+ const container = createContainer();
+ await render(
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
diff --git a/packages/components/src/truncate/test/index.tsx b/packages/components/src/truncate/test/index.tsx
index 399393a25e420..ea86f1794225a 100644
--- a/packages/components/src/truncate/test/index.tsx
+++ b/packages/components/src/truncate/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
diff --git a/packages/components/src/unit-control/test/index.tsx b/packages/components/src/unit-control/test/index.tsx
index d91498d46478b..df6c97f416a83 100644
--- a/packages/components/src/unit-control/test/index.tsx
+++ b/packages/components/src/unit-control/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
import userEvent from '@testing-library/user-event';
/**
@@ -15,6 +16,12 @@ import { useState } from '@wordpress/element';
import UnitControl from '..';
import { CSS_UNITS, parseQuantityAndUnitFromRawValue } from '../utils';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
const getInput = ( {
isInputTypeText = false,
}: {
@@ -85,8 +92,8 @@ const ControlledSyncUnits = () => {
describe( 'UnitControl', () => {
describe( 'Basic rendering', () => {
- it( 'should render', () => {
- render( );
+ it( 'should render', async () => {
+ await render( );
const input = getInput();
const select = getSelect();
@@ -94,12 +101,16 @@ describe( 'UnitControl', () => {
expect( select ).toBeInTheDocument();
} );
- it( 'should render custom className', () => {
- const { container: withoutClassName } = render( );
+ it( 'should render custom className', async () => {
+ const withoutClassName = createContainer();
+ await render( , {
+ container: withoutClassName,
+ } );
- const { container: withClassName } = render(
-
- );
+ const withClassName = createContainer();
+ await render( , {
+ container: withClassName,
+ } );
expect(
// eslint-disable-next-line testing-library/no-node-access
@@ -111,8 +122,8 @@ describe( 'UnitControl', () => {
).toHaveClass( 'hello' );
} );
- it( 'should not render select, if units are disabled', () => {
- render( );
+ it( 'should not render select, if units are disabled', async () => {
+ await render( );
const input = getInput();
// Using `queryByRole` instead of `getSelect` because we need to test
// for this element NOT to be in the document.
@@ -122,8 +133,10 @@ describe( 'UnitControl', () => {
expect( select ).not.toBeInTheDocument();
} );
- it( 'should render label if single units', () => {
- render( );
+ it( 'should render label if single units', async () => {
+ await render(
+
+ );
const select = screen.queryByRole( 'combobox' );
const label = screen.getByText( '%' );
@@ -138,7 +151,9 @@ describe( 'UnitControl', () => {
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render( );
+ await render(
+
+ );
const input = getInput();
await user.clear( input );
@@ -159,7 +174,9 @@ describe( 'UnitControl', () => {
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render( );
+ await render(
+
+ );
const input = getInput();
await user.type( input, '{ArrowUp}' );
@@ -175,7 +192,9 @@ describe( 'UnitControl', () => {
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render( );
+ await render(
+
+ );
const input = getInput();
await user.type( input, '{Shift>}{ArrowUp}{/Shift}' );
@@ -191,7 +210,9 @@ describe( 'UnitControl', () => {
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render( );
+ await render(
+
+ );
const input = getInput();
await user.type( input, '{ArrowDown}' );
@@ -207,7 +228,9 @@ describe( 'UnitControl', () => {
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render( );
+ await render(
+
+ );
const input = getInput();
await user.type( input, '{Shift>}{ArrowDown}{/Shift}' );
@@ -223,7 +246,7 @@ describe( 'UnitControl', () => {
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render(
+ await render(
{
const onChangeSpy = jest.fn();
const onBlurSpy = jest.fn();
- render(
+ await render(
{
const onChangeSpy = jest.fn();
- render(
+ await render(
{
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render(
+ await render(
<>
Click me
{
const onChangeSpy = jest.fn();
const onUnitChangeSpy = jest.fn();
- render(
+ await render(
{
);
} );
- it( 'should render customized units, if defined', () => {
+ it( 'should render customized units, if defined', async () => {
const units = [
{ value: 'pt', label: 'pt', default: 0 },
{ value: 'vmax', label: 'vmax', default: 10 },
@@ -377,7 +400,7 @@ describe( 'UnitControl', () => {
{ value: '+', label: '+', default: 10 },
];
- render( );
+ await render( );
const options = getSelectOptions();
@@ -399,7 +422,7 @@ describe( 'UnitControl', () => {
{ value: 'vmax', label: 'vmax', default: 75 },
];
- render(
+ await render(
{
{ value: 'vmax', label: 'vmax', default: 75 },
];
- render(
+ await render(
{
const user = userEvent.setup();
const onChangeSpy = jest.fn();
- render(
+ await render(
{
it( 'should update unit value when a new raw value is passed', async () => {
const user = userEvent.setup();
- render( );
+ await render( );
const [ inputA, inputB ] = screen.getAllByRole( 'spinbutton' );
const [ selectA, selectB ] = screen.getAllByRole( 'combobox' );
@@ -527,7 +550,7 @@ describe( 'UnitControl', () => {
{ value: 'vmax', label: 'vmax' },
];
- render( );
+ await render( );
const select = getSelect();
await user.selectOptions( select, [ 'vmax' ] );
@@ -544,7 +567,7 @@ describe( 'UnitControl', () => {
const onUnitChangeSpy = jest.fn();
const onBlurSpy = jest.fn();
- render(
+ await render(
{
describe( 'Unit Parser', () => {
it( 'should update unit after initial render and with new unit prop', async () => {
- const { rerender } = render( );
+ const { rerender } = await render( );
const select = getSelect();
expect( select.value ).toBe( '%' );
- rerender( );
+ await rerender( );
expect( select.value ).toBe( 'vh' );
} );
- it( 'should fallback to default unit if parsed unit is invalid', () => {
- render( );
+ it( 'should fallback to default unit if parsed unit is invalid', async () => {
+ await render( );
expect( getSelect().value ).toBe( 'px' );
} );
- it( 'should display valid CSS unit when not explicitly included in units list', () => {
- render(
+ it( 'should display valid CSS unit when not explicitly included in units list', async () => {
+ await render(
{
);
};
- it( 'should use incoming prop as state on initial render', () => {
+ it( 'should use incoming prop as state on initial render', async () => {
const spy = jest.fn();
- render( );
+ await render( );
const input = getInput();
@@ -45,9 +46,9 @@ describe( 'hooks', () => {
expect( spy ).not.toHaveBeenCalled();
} );
- it( 'should update rendered value onChange', () => {
+ it( 'should update rendered value onChange', async () => {
const spy = jest.fn();
- render( );
+ await render( );
const input = getInput();
@@ -73,7 +74,7 @@ describe( 'hooks', () => {
* Unlike the basic useState hook, useControlledState's state can
* be updated if a new incoming prop value is changed.
*/
- it( 'should update changed value with new incoming prop value', () => {
+ it( 'should update changed value with new incoming prop value', async () => {
const spy = jest.fn();
/**
@@ -81,7 +82,7 @@ describe( 'hooks', () => {
* from props. The prop being rendered is the state provided by
* useControlledState, rather than the value prop directly.
*/
- const { rerender } = render( );
+ const { rerender } = await render( );
const input = getInput();
@@ -97,16 +98,16 @@ describe( 'hooks', () => {
* internal state value, which will be rerendered into
* the .
*/
- rerender( );
+ await rerender( );
expect( input.value ).toBe( 'New Value' );
expect( spy ).toHaveBeenCalledTimes( 1 );
} );
- it( 'should render with initial value and be controllable', () => {
+ it( 'should render with initial value and be controllable', async () => {
const spy = jest.fn();
// Input starts off as being uncontrolled / self-managed.
- const { rerender } = render(
+ const { rerender } = await render(
);
const input = getInput();
@@ -119,7 +120,7 @@ describe( 'hooks', () => {
expect( spy ).toHaveBeenCalledWith( 'There' );
// Input is now controlled.
- rerender( );
+ await rerender( );
expect( input.value ).toBe( 'New Value' );
fireEvent.change( input, {
diff --git a/packages/components/src/utils/hooks/test/use-controlled-value.js b/packages/components/src/utils/hooks/test/use-controlled-value.js
index 1e89cd5e81621..c8b7a1461ecc1 100644
--- a/packages/components/src/utils/hooks/test/use-controlled-value.js
+++ b/packages/components/src/utils/hooks/test/use-controlled-value.js
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { fireEvent, render, screen } from '@testing-library/react';
+import { fireEvent, screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -23,24 +24,28 @@ function getInput() {
}
describe( 'useControlledValue', () => {
- it( 'should use the default value', () => {
- render( );
+ it( 'should use the default value', async () => {
+ await render( );
expect( getInput() ).toHaveValue( 'WordPress.org' );
} );
- it( 'should use the default value then switch to the controlled value', () => {
- const { rerender } = render( );
+ it( 'should use the default value then switch to the controlled value', async () => {
+ const { rerender } = await render(
+
+ );
expect( getInput() ).toHaveValue( 'WordPress.org' );
- rerender(
+ await rerender(
);
expect( getInput() ).toHaveValue( 'Code is Poetry' );
} );
- it( 'should call onChange only when there is no value being passed in', () => {
+ it( 'should call onChange only when there is no value being passed in', async () => {
const onChange = jest.fn();
- render( );
+ await render(
+
+ );
expect( getInput() ).toHaveValue( 'WordPress.org' );
@@ -50,9 +55,9 @@ describe( 'useControlledValue', () => {
expect( onChange ).toHaveBeenCalledWith( 'Code is Poetry' );
} );
- it( 'should call onChange when there is a value passed in', () => {
+ it( 'should call onChange when there is a value passed in', async () => {
const onChange = jest.fn();
- const { rerender } = render(
+ const { rerender } = await render(
{
target: { value: 'WordPress rocks!' },
} );
- rerender(
+ await rerender(
{
expect( onChange ).toHaveBeenCalledWith( 'WordPress rocks!' );
} );
- it( 'should not maintain internal state if no onChange is passed but a value is passed', () => {
- const { rerender } = render( );
+ it( 'should not maintain internal state if no onChange is passed but a value is passed', async () => {
+ const { rerender } = await render( );
expect( getInput() ).toHaveValue( 'Code is Poetry' );
@@ -94,7 +99,7 @@ describe( 'useControlledValue', () => {
expect( getInput() ).toHaveValue( 'Code is Poetry' );
// Next we un-set the value to uncover the internal state which was still maintained.
- rerender( );
+ await rerender( );
expect( getInput() ).toHaveValue( 'WordPress.org' );
} );
diff --git a/packages/components/src/utils/hooks/test/use-cx.js b/packages/components/src/utils/hooks/test/use-cx.js
index 181e0beeca2a4..1259fb9510e18 100644
--- a/packages/components/src/utils/hooks/test/use-cx.js
+++ b/packages/components/src/utils/hooks/test/use-cx.js
@@ -4,7 +4,8 @@
// eslint-disable-next-line no-restricted-imports
import { cx as innerCx } from '@emotion/css';
import { insertStyles } from '@emotion/utils';
-import { render } from '@testing-library/react';
+
+import { render } from '@ariakit/test/react';
import { css, CacheProvider } from '@emotion/react';
import createCache from '@emotion/cache';
@@ -28,7 +29,7 @@ function Example( { args } ) {
}
describe( 'useCx', () => {
- it( 'should call cx with the built style name and pass serialized styles to insertStyles', () => {
+ it( 'should call cx with the built style name and pass serialized styles to insertStyles', async () => {
const serializedStyle = css`
color: red;
`;
@@ -43,7 +44,7 @@ describe( 'useCx', () => {
const cache = createCache( { container, key } );
- render(
+ await render(
diff --git a/packages/components/src/v-stack/test/index.tsx b/packages/components/src/v-stack/test/index.tsx
index e8ea1ab0ee396..4b863fe2ab8f9 100644
--- a/packages/components/src/v-stack/test/index.tsx
+++ b/packages/components/src/v-stack/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render } from '@testing-library/react';
+
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -9,33 +10,45 @@ import { render } from '@testing-library/react';
import { View } from '../../view';
import { VStack } from '..';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
describe( 'props', () => {
- test( 'should render correctly', () => {
- const { container } = render(
+ test( 'should render correctly', async () => {
+ const container = createContainer();
+ await render(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- test( 'should render alignment', () => {
- const { container } = render(
+ test( 'should render alignment', async () => {
+ const container = createContainer();
+ await render(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- test( 'should render spacing', () => {
- const { container } = render(
+ test( 'should render spacing', async () => {
+ const container = createContainer();
+ await render(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
diff --git a/packages/components/src/view/test/index.js b/packages/components/src/view/test/index.js
index 56c6f7cd7a148..bef7f2d5c695a 100644
--- a/packages/components/src/view/test/index.js
+++ b/packages/components/src/view/test/index.js
@@ -1,34 +1,45 @@
/**
* External dependencies
*/
-import { render } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
*/
import { View } from '../index';
+function createContainer() {
+ const container = document.createElement( 'div' );
+ document.body.appendChild( container );
+ return container;
+}
+
describe( 'props', () => {
- test( 'should render correctly', () => {
- const { container } = render(
+ test( 'should render correctly', async () => {
+ const container = createContainer();
+ await render(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- test( 'should render as another element', () => {
- const { container } = render(
+ test( 'should render as another element', async () => {
+ const container = createContainer();
+ await render(
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- test( 'should render with custom styles (string)', () => {
- const { container } = render(
+ test( 'should render with custom styles (string)', async () => {
+ const container = createContainer();
+ await render(
{
` }
>
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- test( 'should render with custom styles (object)', () => {
- const { container } = render(
+ test( 'should render with custom styles (object)', async () => {
+ const container = createContainer();
+ await render(
{
} }
>
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
- test( 'should render with custom styles (Array)', () => {
- const { container } = render(
+ test( 'should render with custom styles (Array)', async () => {
+ const container = createContainer();
+ await render(
{
] }
>
-
+ ,
+ { container }
);
expect( container ).toMatchSnapshot();
} );
diff --git a/packages/components/src/visually-hidden/test/index.tsx b/packages/components/src/visually-hidden/test/index.tsx
index 9c66dbe4685a8..fcadad3d14acc 100644
--- a/packages/components/src/visually-hidden/test/index.tsx
+++ b/packages/components/src/visually-hidden/test/index.tsx
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
+import { render } from '@ariakit/test/react';
/**
* Internal dependencies
@@ -9,9 +10,9 @@ import { render, screen } from '@testing-library/react';
import { VisuallyHidden } from '..';
describe( 'VisuallyHidden', () => {
- it( 'should render correctly', () => {
+ it( 'should render correctly', async () => {
const text = 'This is hidden';
- render( { text } );
+ await render( { text } );
expect( screen.getByText( text ) ).toMatchSnapshot();
} );
} );