Accepted answer

short answer: don't.

testing an internal state variable very much goes against the philosophy behind react-testing-library. that lib is focused on the user, and what the user can see. the user has no concept of a state variable. instead of testing that, think of the changes the user would see, and test for that. how is the ui updated? what different markup or styling is displayed? consider how to test from the user's perspective, and you'll find your answers.

check out react-testing-library's guiding principles for more context. then take a look through this page for guidelines on which queries make the most sense for your use case.

Related Query

More Query from same tag