首页 > 解决方案 > 如何访问测试文件中的 props 值组件(Jest 和 Enzyme)

问题描述

如何访问测试文件(Jest 和 Enzyme)中组件中的 props 值?这是我的组件,我想访问测试文件(Jest 和 Enzyme)中 Pin 组件中的 prop 值,可以吗?

<View style={styles.containerForm}>
  <Text style={styles.textDescriptionGreyFont}>Enter Code</Text>
  <Pin testID={'input_pin'} count={4} value={otp} setCode={(code) => setOtpCode(code)} />
  <View style={styles.containerResendTimer}>
    {renderResend()}
    <Text style={styles.textDescriptionThemaFont}>{renderTimer()}</Text>
  </View>
  <ButtonFull
    testID={'submit_otp'}
    isDisabled={false}
    buttonColor={fullFilled ? color.thema : color.disabledButton}
    onPress={() => submitOtp()}
    title={submitting ? 'Loading ...' : 'Submit'}
  />
</View>

标签: react-nativejestjsenzyme

解决方案


我找到了解决方案,

expect(appWrapper.find('Pin').prop('value')).toBe('')
expect(appWrapper.find('ButtonFull').prop('isDisabled')).toBe(true)

推荐阅读