React-testing-library: Found multiple elements by: [data-testid=

Created on 19 Nov 2019  路  3Comments  路  Source: testing-library/react-testing-library

can anyone explain how can the message Found multiple elements by, actually in the component there is only 1 data-testid,

@testing-library/jest-dom": "4.0.0
@testing-library/react": "^8.0.9,
"react": "^16.12.0",

"react-dom": "^16.12.0",

image

Most helpful comment

Guys, i've just had this error and was easy to solve the problem.
I was changing branchs, and because of that my node_modules was different from what the package.json file.
To solve this i've just reinstalled the node_modules from scratch and worked fine!
The cleanup wasn't running correctly because some problem with version in my node_modules
Maybe this can help anyone with same problems!

All 3 comments

We would more information then this. Coul you post a reproducible sandbox example? Without code is a bit hard to see what could be going wrong here. Are you sure you are cleaning up after each test?

Hi @nagacoder,

Thanks @weyert! @weyert is correct, we'd need more information than this to help and a reproduction would really help. In addition, issues like this are best if posted to https://spectrum.chat/testing-library/help-react

Also, for @weyert:

Are you sure you are cleaning up after each test?

That's automatic now, you shouldn't need to worry about it. :)

I'm going to go ahead and close this. Please take this to spectrum. Thanks @nagacoder!

Guys, i've just had this error and was easy to solve the problem.
I was changing branchs, and because of that my node_modules was different from what the package.json file.
To solve this i've just reinstalled the node_modules from scratch and worked fine!
The cleanup wasn't running correctly because some problem with version in my node_modules
Maybe this can help anyone with same problems!

Was this page helpful?
0 / 5 - 0 ratings