Skip to content

Commit 61aa8f5

Browse files
tyxlamirka
andauthored
Components: Try fixing some flaky Composite and Tabs tests (#58968)
* Components: Try fixing some flaky Composite and Tabs tests * Add extra sleep() to make less flaky Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: mirka <0mirka00@git.wordpress.org>
1 parent 6a7f83c commit 61aa8f5

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎packages/components/src/composite/legacy/test/index.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* External dependencies
33
*/
44
import { queryByAttribute, render, screen } from '@testing-library/react';
5-
import { press, waitFor } from '@ariakit/test';
5+
import { press, sleep, waitFor } from '@ariakit/test';
66

77
/**
88
* Internal dependencies
@@ -274,8 +274,9 @@ describe.each( [
274274
renderAndValidate( <Test /> );
275275
const { item2 } = getOneDimensionalItems();
276276

277+
await sleep();
277278
await press.Tab();
278-
expect( item2 ).toHaveFocus();
279+
await waitFor( () => expect( item2 ).toHaveFocus() );
279280
} );
280281
} );
281282

‎packages/components/src/tabs/test/index.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,10 +1319,13 @@ describe( 'Tabs', () => {
13191319
expect( await getSelectedTab() ).toHaveTextContent( 'Beta' );
13201320

13211321
// Tab key should focus the currently selected tab, which is Beta.
1322+
await sleep();
13221323
await press.Tab();
1323-
expect(
1324-
await screen.findByRole( 'tab', { name: 'Beta' } )
1325-
).toHaveFocus();
1324+
await waitFor( async () =>
1325+
expect(
1326+
await screen.findByRole( 'tab', { name: 'Beta' } )
1327+
).toHaveFocus()
1328+
);
13261329

13271330
// Arrow key should move focus but not automatically change the selected tab.
13281331
await press.ArrowRight();

0 commit comments

Comments
 (0)