react-native-testing-library
react-native-testing-library copied to clipboard
How to use queries on rerendered component
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.log
s 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.
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.
Closing as stale.