react-native-testing-library icon indicating copy to clipboard operation
react-native-testing-library copied to clipboard

How to use queries on rerendered component

Open erikmueller opened this issue 4 years ago • 1 comments

First: I love the library and how it encourages best testing pratices!

I don't know if I missed the part in the docs that describes that but I am unable to query component (tree) updates after having done a rerender (update). The code in componentDidUpdate works just fine and is easy to test but once I try to re-query elements (getAllByA11yLabel) I seem to get back the old elements (the conole.logs in the component tell me it's rerendering with correct new props)

Am I missing sth or is this just not possible (I noticed update returns void rather than new utils bound to the new tree)

Thanks.

erikmueller avatar Mar 31 '20 19:03 erikmueller

That's a great question. Short answer: this won't work with how we currently build queries (hint: closures). You can see the updated tree with debug for example, but the React Test Renderer instance is closed over in queries and doesn't respond to mutation done by its update function.

We can think about how to achieve this without changes to the public API of the library, but it's not a priority at the moment. Feel free to play with it yourself and let us know your findings :)

In the meantime, you verify a certain update happened through component props.

thymikee avatar Mar 31 '20 20:03 thymikee

Closing as stale.

mdjastrzebski avatar Sep 26 '22 12:09 mdjastrzebski