question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to find the suggestion items during a unit test

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

10reactions
dallin-christensencommented, Mar 15, 2019

if anyone’s still interested in this… I got that codepen working by inserting

inputNode.focus()

into line 17 in Autocomplete.test.js 👍

1reaction
gazpachucommented, Nov 14, 2018

Here is sandbox that another user made to show the issue: https://codesandbox.io/s/5yzq54p8yl

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unit test failing on Unable to find elements - Stack Overflow
A) TestingLibraryElementError: Unable to find an element with the text: Visit my page. This could be because the text is broken up by...
Read more >
How do you detect dependency problems with unit tests when ...
M.e. a better strategy is to have good separation of concerns (e.g. you can test Part A of your app without bringing in...
Read more >
Test Explorer not discoverying test methods
I created one test method in a test project in a solution, did a build, test explorer not ... Unable to get consistent...
Read more >
Fix Your Failing Tests: A Debugging Checklist for React ...
Unable to find an element with the text: ${text}. This could be because the text is broken up by multiple elements. In this...
Read more >
Hilt testing guide | Android Developers
Multiple TestRule objects in your instrumented test · class SettingsActivityTest { @get:Rule var rule = RuleChain.outerRule(HiltAndroidRule(this)). around( ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found