Skip to content

Commit e60441c

Browse files
codegen-sh[bot]Jake Ruesink
andcommitted
Fix CreatableOption test: improve async handling for portaled dropdown
- Replace setTimeout with proper await for listbox and search input elements - Use findByRole and findByPlaceholderText for better async handling - Ensures dropdown and search input are fully rendered before interaction - Fixes race condition that was causing 'Unable to find role=listbox' error Co-authored-by: Jake Ruesink <jake@lambdacurry.com>
1 parent 1d37c02 commit e60441c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

apps/docs/src/remix-hook-form/select.stories.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,12 @@ export const CreatableOption: Story = {
511511
// Wait for the component to render before interacting
512512
const regionSelect = await canvas.findByLabelText('Custom Region');
513513
await userEvent.click(regionSelect);
514-
// Add a small delay to ensure the dropdown has time to render
515-
await new Promise((resolve) => setTimeout(resolve, 100));
514+
515+
// Wait for the dropdown to appear in the portal
516516
const listbox = await within(document.body).findByRole('listbox');
517+
517518
// The search input is outside the listbox container; query from the portal root
518-
const input = within(document.body).getByPlaceholderText('Search...');
519+
const input = await within(document.body).findByPlaceholderText('Search...');
519520
await userEvent.click(input);
520521
await userEvent.clear(input);
521522
await userEvent.type(input, 'Atlantis');
@@ -535,11 +536,12 @@ export const CreatableOption: Story = {
535536
// Wait for the component to render before interacting
536537
const regionSelect = await canvas.findByLabelText('Custom Region');
537538
await userEvent.click(regionSelect);
538-
// Add a small delay to ensure the dropdown has time to render
539-
await new Promise((resolve) => setTimeout(resolve, 100));
539+
540+
// Wait for the dropdown to appear in the portal
540541
const listbox = await within(document.body).findByRole('listbox');
542+
541543
// The search input is outside the listbox container; query from the portal root
542-
const input = within(document.body).getByPlaceholderText('Search...');
544+
const input = await within(document.body).findByPlaceholderText('Search...');
543545
await userEvent.click(input);
544546
await userEvent.clear(input);
545547
await userEvent.type(input, 'California');

0 commit comments

Comments
 (0)