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

fix: do not render mocked Modal when visible=false #39157

Closed

Conversation

mdjastrzebski
Copy link
Contributor

@mdjastrzebski mdjastrzebski commented Aug 25, 2023

Summary:

Note: this PR is related only to testing mocks provided by RN, and does not affect runtime code.

When building new Jest matchers for React Native Testing Library (callstack/react-native-testing-library#1468) I've noticed that when rendering React Native in Jest using React Test Renderer the mocked Modal component renders host Modal element when visible={false}.

This seems to be incorrect as only visible modal should render any host elements. Not visible one should not render any host element even empty ones. Current mock implementation also contradicts the behaviour of non-mocked Modal which does not render RCTModalHostView in such case.

Changelog:

[General] [Fixed] - Do not render mocked when visible=false

Test Plan:

I've added test showing that non-mocked Modal renders to null and modifies the existing tests so that mocked Modal also renders to null.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 25, 2023
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 25, 2023
@analysis-bot
Copy link

analysis-bot commented Aug 25, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,960,135 -18
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 9,554,202 -6
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 3c87455
Branch: main

@mdjastrzebski
Copy link
Contributor Author

The failure in test_e2e_android check does not seem to be related to this PR.

@@ -13,7 +13,7 @@ exports[`<Modal /> should render as <RCTModalHostView> when not mocked 1`] = `
<RCTModalHostView
animationType="none"
hardwareAccelerated={false}
identifier={4}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What caused this to change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I happens due to Modal keeping auto-incrementing identifier for each composite Modal instance. Since tests are not isolated, the removal of rendering of Modal when visible={false} in previous test reduced the count by 1.

@facebook-github-bot
Copy link
Contributor

@lunaleaps has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@github-actions
Copy link

This pull request was successfully merged by @mdjastrzebski in 468a136.

When will my fix make it into a release? | Upcoming Releases

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Aug 30, 2023
@github-actions github-actions bot added the Merged This PR has been merged. label Aug 30, 2023
@facebook-github-bot
Copy link
Contributor

@lunaleaps merged this pull request in 468a136.

@mdjastrzebski mdjastrzebski deleted the fix/modal-mock-render branch August 30, 2023 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants