Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec.press resulting in error for non Button components #191

Open
fuzzpedal opened this issue Jun 30, 2020 · 7 comments
Open

spec.press resulting in error for non Button components #191

fuzzpedal opened this issue Jun 30, 2020 · 7 comments

Comments

@fuzzpedal
Copy link

spec.press is working for Button components but I get the following error for TouchableHighlight and TouchableOpacity components:
undefined is not an object (evaluating 'component.props.onPress')

I'm using expo and typescript if that makes a difference.

@PolarisWT
Copy link

This is happening in my project as well. Tried upgrading cavy to v4.0.0 and cavy-cli v2.0.0. After some internal testing, it appears it may be related to a change in React Native v0.62. Downgrading to RN 0.61, tests run okay. This is true for cavy v4 and v3.x (with appropriate cli).

Major overhaul of Touchable[...] components may the cause...
https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#removed

Looks the removal of propTypes (which contained the handler mixin function for onPress for these actions) in favor of the new Pressability feature.

press action either needs to be expanded to account for Pressability states, or new actions created
https://github.com/pixielabs/cavy/blob/master/src/TestScope.js#L147

@fuzzpedal
Copy link
Author

@PolarisWT that's really helpful, thanks!

@AbigailMcP
Copy link
Contributor

Thanks for delving into this @PolarisWT, really useful findings! @fuzzpedal - did you find that you were able to swap to using the Pressable component with spec.press?

Looks like we have a couple of things it would be good to address Cavy-side:

  • Our sample app is using React Native 0.59, and shows TouchableHighlight being used with spec.press. This needs to be updated.
  • We should add something to the docs about using Cavy with TouchableHighlights / Capacity, whether this is just a not on React Native versions for now, or a workaround, I'm not quite sure without investigating further.
  • It would be nice to support all Pressable props.

I'll add these to the public backlog!

Note that if there isn't a Cavy helper function that calls the exact prop you need, you can always use spec.findComponent and call the props on the component yourself. This might be useful for interacting with Pressable for the time being.

@AbigailMcP AbigailMcP self-assigned this Jul 3, 2020
@PolarisWT
Copy link

PolarisWT commented Jul 26, 2020

Note that if there isn't a Cavy helper function that calls the exact prop you need, you can always use spec.findComponent and call the props on the component yourself. This might be useful for interacting with Pressable for the time being.

^^^ Great! Got the onPress() firing with help from this post you did on issue #101 (comment).

Referenced for anyone else running across this issue as spec.findComponent did not work right out of the box on some components without wrap() for me

@Duy1999
Copy link

Duy1999 commented Aug 6, 2020

@AbigailMcP How can you work on the checkBox component? i try using hook and wrap but it got the error:
component.props.onPress is not a function. (In 'component.props.onPress()', 'component.props.onPress' is undefined)

also, how can we use cavy with the bottom tabs created like this
Capture

@AbigailMcP
Copy link
Contributor

Hi @Duy1999 ! Sorry I haven't been able to look into this sooner.

Checkboxes
Firstly, can I confirm that it's the react-native-checkbox you're using from react-native-community?

I assume you're getting the component.props.onPress error when you're using cavy's spec.press() function. This called the component's onPress prop underneath the hook, but it sounds as though this isn't a prop on your checkbox. Is there a prop you can call instead, like props.onValueChange?

If so, you can use cavy's findComponent() function to return your checkbox component, and call the correct prop directly yourself.

Let me know how you get on with this. In the future, it might be nice for Cavy to support checking checkboxes, as they're a common form element! I'll add this to Cavy's product backlog for consideration :)

Stack Navigator
I don't actually have any personal experience integrating Cavy with this style of navigation set up.. and I can't think of anything obvious to suggest at the moment! Looking at the docs, there's tabBarButtonComponent, which you could try adding a ref to, but that sounds less than ideal.

Paging @jalada in case he has any ideas!

@jalada
Copy link
Contributor

jalada commented Aug 24, 2020

Re: Stack Navigator, a custom component was my first thought as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants