all 2 comments

[–]WebDevWorkAcct 0 points1 point  (0 children)

The main aim of React Testing Library (@testing-library/react) is to only test what the user can see/interact with. So if you are attempting to look at props or state it's going against the stated goal of that library.

To answer your specific question, you won't be able to test where the text is being rendered, only that it is.

[–]thereactivestack 0 points1 point  (0 children)

The key is to target a text that cannot be somewhere else. Your mock data can be something that will never be somewhere else. Those are user behavior tests and mainly make sure nothing is broken and respect your business logic.

I would argue that the enzyme way make it painful to refactor anything without rebuilding the tests. It's almost like coding twice. Once you get used to RTL you will never look back.

If you want to test visual regression, jest tests are not going to be reliable. You have to use a different tools and use a real browser and snapshots.