Javascript 解毒-在react native中测试模态的可见性
我们正在使用detox编写react本机应用程序的E2E测试,其中我们有一个案例需要测试点击按钮后是否出现模态 但是Detoxit无法用给定的Javascript 解毒-在react native中测试模态的可见性,javascript,testing,react-native,integration-testing,detox,Javascript,Testing,React Native,Integration Testing,Detox,我们正在使用detox编写react本机应用程序的E2E测试,其中我们有一个案例需要测试点击按钮后是否出现模态 但是Detoxit无法用给定的testID识别模态,因为模态按预期打开。是否有一种不同的方式测试模式在反应性使用排毒 下面是模态JSX <Modal testID="loadingModal" animationType="none" transparent visible={loading} onRequestClose={() =>
testID
识别模态,因为模态按预期打开。是否有一种不同的方式测试模式在反应性使用排毒
下面是模态JSX
<Modal
testID="loadingModal"
animationType="none"
transparent
visible={loading}
onRequestClose={() => {}}
>
<View style={styles.modalContainer}>
<View style={styles.loginModal}>
<ActivityIndicator
animating
size="large"
color="#00e0ff"
/>
<Text style={styles.login}>Logging in...</Text>
</View>
</View>
</Modal>
React Native的模态组件创建一个视图控制器,该控制器在本机级别上管理子视图的渲染。不幸的是,它没有传递testID,因此我发现最好的方法是将模态的内容包装在
中,并将testID属性传递给该组件。在您的情况下,您可以:
<Modal
animationType="none"
transparent
visible={loading}
onRequestClose={() => {}}
>
<View
style={styles.modalContainer}
testID="loadingModal" // Just move the testID to this element
>
<View style={styles.loginModal}>
<ActivityIndicator
animating
size="large"
color="#00e0ff"
/>
<Text style={styles.login}>Logging in...</Text>
</View>
</View>
{}
>
正在登录。。。
<Modal
animationType="none"
transparent
visible={loading}
onRequestClose={() => {}}
>
<View
style={styles.modalContainer}
testID="loadingModal" // Just move the testID to this element
>
<View style={styles.loginModal}>
<ActivityIndicator
animating
size="large"
color="#00e0ff"
/>
<Text style={styles.login}>Logging in...</Text>
</View>
</View>