-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Update Modal's mock to not render its children when it is not visible #32346
Update Modal's mock to not render its children when it is not visible #32346
Conversation
f6faa13
to
cdab5f0
Compare
Base commit: 3562364 |
Base commit: 3562364 |
@lunaleaps has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Totally agree with this proposition, I've had this issue more than once where I had to use visible prop in my tests |
Fantastic, I've been needing this as well 😊 It is a breaking change though. It needs to be documented as such since it will break some people's tests upon upgrade! |
This pull request was successfully merged by @AntoineDoubovetzky in ec614c1. When will my fix make it into a release? | Upcoming Releases |
… visible (facebook#32346)" This reverts commit ec614c1.
… visible (facebook#32346)" This reverts commit ec614c1.
… visible (facebook#32346)" This reverts commit ec614c1.
… visible (facebook#32346)" This reverts commit ec614c1.
… visible (facebook#32346)" This reverts commit ec614c1.
… visible (facebook#32346)" This reverts commit ec614c1.
… visible (facebook#32346)" This reverts commit ec614c1.
… visible (facebook#32346)" This reverts commit ec614c1.
Summary
The Modal's mock always render its children (whether it is visible or not), whereas in reality the Modal renders
null
when the Modal is not visible.This causes troubles when trying to test whether the Modal is visible or not. Instead of testing if the children are rendered (using getByText from React Native Testing Library for instance), we are forced to test the value of the visible prop directly (see callstack/react-native-testing-library#508 and callstack/react-native-testing-library#659).
This is not ideal because we are forced to test implementation detail and can't test from the user perspective. I also believe the mock should be as close as possible from reality.
I had 2 options:
The latter has the advantage of being closer to the reality, but I chose the former to still be able to test the Modal through the visible prop, so there is no breaking change (only snapshots update will be required).
Changelog
[General] [Changed] - Update Modal's mock to not render its children when it is not visible.⚠️ Snapshots containing Modal with
visible={false}
will have to be updated.Test Plan
I added a test case when visible is false, then updated the mock so the children are not rendered. The before / after is here: