Skip to content

Commit 377316a

Browse files
ciampotyxla
authored andcommitted
Composite: always await initial render setup in unit tests (#65823)
Co-authored-by: ciampo <[email protected]> Co-authored-by: tyxla <[email protected]>
1 parent 5ab5789 commit 377316a

File tree

1 file changed

+22
-21
lines changed
  • packages/components/src/composite/legacy/test

1 file changed

+22
-21
lines changed

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

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ describe.each( [
232232
<button>After</button>
233233
</>
234234
);
235-
renderAndValidate( <Test /> );
235+
await renderAndValidate( <Test /> );
236236

237237
await press.Tab();
238238
expect( screen.getByText( 'Before' ) ).toHaveFocus();
@@ -260,7 +260,7 @@ describe.each( [
260260
</Composite>
261261
);
262262
};
263-
renderAndValidate( <Test /> );
263+
await renderAndValidate( <Test /> );
264264

265265
const { item1, item2, item3 } = getOneDimensionalItems();
266266

@@ -289,7 +289,7 @@ describe.each( [
289289
</Composite>
290290
);
291291
};
292-
renderAndValidate( <Test /> );
292+
await renderAndValidate( <Test /> );
293293
const { item1, item2, item3 } = getOneDimensionalItems();
294294

295295
expect( item2 ).toBeEnabled();
@@ -310,7 +310,7 @@ describe.each( [
310310
} ) }
311311
/>
312312
);
313-
renderAndValidate( <Test /> );
313+
await renderAndValidate( <Test /> );
314314
const { item1, item2, item3 } = getOneDimensionalItems();
315315

316316
expect( item1.id ).toMatch( 'test-id-1' );
@@ -327,7 +327,7 @@ describe.each( [
327327
} ) }
328328
/>
329329
);
330-
renderAndValidate( <Test /> );
330+
await renderAndValidate( <Test /> );
331331
const { item2 } = getOneDimensionalItems();
332332

333333
await press.Tab();
@@ -341,37 +341,37 @@ describe.each( [
341341
] )( '%s', ( _when, rtl ) => {
342342
const { previous, next, first, last } = getKeys( rtl );
343343

344-
function useOneDimensionalTest( initialState?: InitialState ) {
344+
async function useOneDimensionalTest( initialState?: InitialState ) {
345345
const Test = () => (
346346
<OneDimensionalTest
347347
state={ useCompositeState( { rtl, ...initialState } ) }
348348
/>
349349
);
350-
renderAndValidate( <Test /> );
350+
await renderAndValidate( <Test /> );
351351
return getOneDimensionalItems();
352352
}
353353

354-
function useTwoDimensionalTest( initialState?: InitialState ) {
354+
async function useTwoDimensionalTest( initialState?: InitialState ) {
355355
const Test = () => (
356356
<TwoDimensionalTest
357357
state={ useCompositeState( { rtl, ...initialState } ) }
358358
/>
359359
);
360-
renderAndValidate( <Test /> );
360+
await renderAndValidate( <Test /> );
361361
return getTwoDimensionalItems();
362362
}
363363

364-
function useShiftTest( shift: boolean ) {
364+
async function useShiftTest( shift: boolean ) {
365365
const Test = () => (
366366
<ShiftTest state={ useCompositeState( { rtl, shift } ) } />
367367
);
368-
renderAndValidate( <Test /> );
368+
await renderAndValidate( <Test /> );
369369
return getShiftTestItems();
370370
}
371371

372372
describe( 'In one dimension', () => {
373373
test( 'All directions work with no orientation', async () => {
374-
const { item1, item2, item3 } = useOneDimensionalTest();
374+
const { item1, item2, item3 } = await useOneDimensionalTest();
375375

376376
await press.Tab();
377377
expect( item1 ).toHaveFocus();
@@ -406,7 +406,7 @@ describe.each( [
406406
} );
407407

408408
test( 'Only left/right work with horizontal orientation', async () => {
409-
const { item1, item2, item3 } = useOneDimensionalTest( {
409+
const { item1, item2, item3 } = await useOneDimensionalTest( {
410410
orientation: 'horizontal',
411411
} );
412412

@@ -435,7 +435,7 @@ describe.each( [
435435
} );
436436

437437
test( 'Only up/down work with vertical orientation', async () => {
438-
const { item1, item2, item3 } = useOneDimensionalTest( {
438+
const { item1, item2, item3 } = await useOneDimensionalTest( {
439439
orientation: 'vertical',
440440
} );
441441

@@ -464,7 +464,7 @@ describe.each( [
464464
} );
465465

466466
test( 'Focus wraps with loop enabled', async () => {
467-
const { item1, item2, item3 } = useOneDimensionalTest( {
467+
const { item1, item2, item3 } = await useOneDimensionalTest( {
468468
loop: true,
469469
} );
470470

@@ -488,7 +488,7 @@ describe.each( [
488488
describe( 'In two dimensions', () => {
489489
test( 'All directions work as standard', async () => {
490490
const { itemA1, itemA2, itemA3, itemB1, itemB2, itemC1, itemC3 } =
491-
useTwoDimensionalTest();
491+
await useTwoDimensionalTest();
492492

493493
await press.Tab();
494494
expect( itemA1 ).toHaveFocus();
@@ -524,7 +524,7 @@ describe.each( [
524524

525525
test( 'Focus wraps around rows/columns with loop enabled', async () => {
526526
const { itemA1, itemA2, itemA3, itemB1, itemC1, itemC3 } =
527-
useTwoDimensionalTest( { loop: true } );
527+
await useTwoDimensionalTest( { loop: true } );
528528

529529
await press.Tab();
530530
expect( itemA1 ).toHaveFocus();
@@ -548,7 +548,7 @@ describe.each( [
548548

549549
test( 'Focus moves between rows/columns with wrap enabled', async () => {
550550
const { itemA1, itemA2, itemA3, itemB1, itemC1, itemC3 } =
551-
useTwoDimensionalTest( { wrap: true } );
551+
await useTwoDimensionalTest( { wrap: true } );
552552

553553
await press.Tab();
554554
expect( itemA1 ).toHaveFocus();
@@ -577,7 +577,7 @@ describe.each( [
577577
} );
578578

579579
test( 'Focus wraps around start/end with loop and wrap enabled', async () => {
580-
const { itemA1, itemC3 } = useTwoDimensionalTest( {
580+
const { itemA1, itemC3 } = await useTwoDimensionalTest( {
581581
loop: true,
582582
wrap: true,
583583
} );
@@ -595,7 +595,8 @@ describe.each( [
595595
} );
596596

597597
test( 'Focus shifts if vertical neighbour unavailable when shift enabled', async () => {
598-
const { itemA1, itemB1, itemB2, itemC1 } = useShiftTest( true );
598+
const { itemA1, itemB1, itemB2, itemC1 } =
599+
await useShiftTest( true );
599600

600601
await press.Tab();
601602
expect( itemA1 ).toHaveFocus();
@@ -616,7 +617,7 @@ describe.each( [
616617
} );
617618

618619
test( 'Focus does not shift if vertical neighbour unavailable when shift not enabled', async () => {
619-
const { itemA1, itemB1, itemB2 } = useShiftTest( false );
620+
const { itemA1, itemB1, itemB2 } = await useShiftTest( false );
620621

621622
await press.Tab();
622623
expect( itemA1 ).toHaveFocus();

0 commit comments

Comments
 (0)