React native exposes certain props on View
like testID that are super useful for native testing, but have following note attached to them
This disables the 'layout-only view removal' optimization for this view!
After searching for a while I was not able to find information that describes what this optimisation is. Is it significant? If it viable to only set these tests id's in dev mode / dev target? i.e. they will be undefined otherwise?
react-native-on-layout is an npm package that you can include in your app using npm i react-native-on-layout or with yarn add react-native-on-layout . It is a View component that will do this onLayout dance for you and then passes the layout values as parameters to a render prop.
Hello friends, In today's tutorial we would learn about testID prop of Image component in react native. Most of us heard about this prop for the first time. So in easy language the testID prop is used as a unique identifier ID for UI Automation Testing Script.
The most fundamental component for building a UI, View is a container that supports layout with flexbox, style, some touch handling, and accessibility controls. View maps directly to the native view equivalent on whatever platform React Native is running on, whether that is a UIView , <div> , android.
When RN creates the native views from the shadow nodes tree - it performs some optimizations. Views that do not actually show on screen (don't draw anything or just used in JSX to contain and layout their children) can be removed when constructing the native hierarchy. This is why they're called "layout-only" views.
As this warning suggests, a view with the testID
prop will not be removed even if it's a "layout-only" view so it will actually be there when you're performing e2e tests.
Generally speaking, rendering a lot of views can cause performance issues, but using testID
on some views won't make a noticeable difference in performance because:
testID
testID
are probably not "layout-only" views so it makes no difference if you use this prop or not regarding the optimizations.In case you do have "layout-only" views with a testID
, it would be easier to move the testID
to a more suitable view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With