Skip to content

Unable to find the suggestion items during a unit test #591

Open
@gazpachu

Description

@gazpachu

I get a Timed out in waitForElement.

it('calls "onSelect" prop when an item is selected', async () => {
  const onSelect = jest.fn();
  const { getByPlaceholderText, container } = customRender(<AutoComplete placeholder="test" data={data} onSelect={onSelect} />);
  const inputNode = getByPlaceholderText('test');

  // This will write `pete` in the input field
  fireEvent.change(inputNode, { target: { value: 'pete' } });

  const items = await waitForElement(() => {
    container.querySelectorAll('.react-autosuggest__suggestion');
  });

  console.log(items);

  // Fire the click on the first item
  // fireEvent.click(items[0]);
  expect(onSelect).toHaveBeenCalled();
});

More info here: https://spectrum.chat/react-testing-library/help?thread=68e5c2dc-21fa-4b8d-9c6d-3bf2c0613c4a

Any help would be much appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions