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.

Got TestingLibraryElementError when running tests

See original GitHub issue

Hi,

I am trying to test react-select with this library, and I was following documentation, I got TestingLibraryElementError: Found a label with the text of: Food, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.

Here is my code for the test, it is copied directly from documentation. https://github.com/JLFullstack/react-select-testing/blob/master/src/openMenu.test.js

Here is the repository I set up to re-produce this issue. https://github.com/JLFullstack/react-select-testing

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
romgaincommented, Aug 10, 2020

Sorry for the confusion @JLFullstack !

That was an issue with the docs 😞

I updated the example here: https://github.com/romgain/react-select-event/commit/7e4b980288b1195d847966951c542278441a396c

Please, let me know if you have any other issues!

0reactions
romgaincommented, Aug 12, 2020

@JLFullstack

Oh, I see. That’s actually an issue with newer versions of @testing-library/react, not with react-select-event. It’s documented under the “MutationObserver shim removed” breaking change here: https://github.com/testing-library/dom-testing-library/releases/tag/v7.0.0

You can fix it by installing jest-environment-jsdom-sixteen and updating your test script:

  "scripts": {
    ...
-   "test": "react-scripts test --env=dom"
+   "test": "react-scripts test --env=jest-environment-jsdom-sixteen"
    ...
  },

Let me know if you have any other issues!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Jest testing : TestingLibraryElementError: Unable to find ...
I am new to react testing. I want to test this component and get back for example the h3 text what was given...
Read more >
Common mistakes with React Testing Library - Kent C. Dodds
Hi there I created React Testing Library because I wasn't satisfied with the testing landscape at the time. It expanded to DOM Testing...
Read more >
Error: Unable to find an element with text: "My text", while that ...
Describe the bug getByText can find element if text render component with text as not children (See "Steps to Reproduce" below) -const Trans ......
Read more >
Improving React Testing Library tests | Alex Khomenko
When running the test we get an error: TestingLibraryElementError: Unable to find an accessible element with the role "textbox" and name ...
Read more >
Testing Visible Text with React Testing Library's getByText ...
Testing Library's ByText methods allow us search the DOM for matching text. We do that here to confirm the total amount is displayed ......
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