Unable to find the suggestion items during a unit test
See original GitHub issueI 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:
- Created 5 years ago
- Reactions:4
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
if anyone’s still interested in this… I got that codepen working by inserting
into line 17 in Autocomplete.test.js 👍
Here is sandbox that another user made to show the issue: https://codesandbox.io/s/5yzq54p8yl