How to access props value component in test file (Jest and Enzyme)

Viewed 3800

How to access props value in component in test file (Jest and Enzyme)? This is my component, I want to access prop value in Pin component in test file (Jest and Enzyme), is it possible?

<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>
2 Answers

You could find the prop value of Pin component like this

const wrapper = shallow(<Component .... />);
expect(wrapper.find(Pin).props().testID).toBe('input_pin');

I found the solution,

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