-
Notifications
You must be signed in to change notification settings - Fork 84
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
How to interact with checkbox in jest test? #78
Comments
There are some examples to show how to change the value of checkbox outside. Please feel free to let us know if you have any trouble in the test of checkbox |
do you still need a better implementation as a new Button just for testing? This is how I solved it:
The last one is not that much beauty, maybe someone can beautify it a little bit 👍 Edit: Realized it with |
I went ahead with wrapping the checkbox label with a TouchableOpacity and testing the |
Had a similar issue, ended up using this to toggle the checkbox:
Just wanted to add this in case it helps anybody else! |
Thanks @echase03! I would like to add also that in my case, I needed to add an const checkbox = await findByRole('checkbox');
fireEvent(checkbox, 'onValueChange', true); |
I am testing with react-native-testing-library and would like to interact with a couple of checkboxes I have in one of my components.
Using
fireEvent.press(getByA11yLabel('Drivers bag'));
would throw errorI tried calling the onValueChange() like so
getByA11yLabel('Drivers bag').props.onValueChange();
and that would throw errorAll I'm interested in testing is whether an effect would run when the user toggles the checkbox.
The text was updated successfully, but these errors were encountered: