Skip to content

Fix RefreshControl jest mock to forward props#56301

Open
psjostrom wants to merge 1 commit intofacebook:mainfrom
psjostrom:fix/refreshcontrol-mock-forward-props
Open

Fix RefreshControl jest mock to forward props#56301
psjostrom wants to merge 1 commit intofacebook:mainfrom
psjostrom:fix/refreshcontrol-mock-forward-props

Conversation

@psjostrom
Copy link
Copy Markdown

@psjostrom psjostrom commented Apr 1, 2026

Summary:

The RefreshControl jest mock renders <RCTRefreshControl /> without forwarding any props. This is inconsistent with the ScrollView mock, which spreads {...this.props} to its native component.

This has two consequences:

  1. The rendered RefreshControl is invisible to RNTL host queries. Props like testID and accessibilityLabel are not forwarded to the native component, so getByTestId, getByLabelText, etc. cannot find it. The only way to locate it is UNSAFE_getByType.

  2. Props transformed internally by wrapper components are inaccessible. When a component wraps RefreshControl and transforms props before passing them down (e.g. wrapping onRefresh with throttle/debounce), the rendered native component should receive the transformed props. But since the mock discards all props, there is no way to access the transformed values without UNSAFE_getByType. The RNTL-recommended pattern of list.props.refreshControl.props.onRefresh() only gives the original untransformed props from the React element descriptor.

The fix spreads this.props onto RCTRefreshControl in both mock files, matching how the ScrollView mock already works. The HostComponent generic is also updated from {} to RefreshControlProps for proper typing.

Changelog:

[GENERAL] [FIXED] - Forward props in RefreshControl jest mock to make testID, onRefresh, and other props visible to testing library queries

Test Plan:

Before this change, rendering a RefreshControl with testID="my-control" produces:

<RCTRefreshControl />

After this change:

<RCTRefreshControl testID="my-control" onRefresh={[Function]} refreshing={false} ... />

This enables standard RNTL queries:

screen.getByTestId('my-control').props.onRefresh();

Instead of requiring:

screen.UNSAFE_getByType(RefreshControl).props.onRefresh();

@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Apr 1, 2026

Hi @psjostrom!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

The RefreshControl mock renders `<RCTRefreshControl />` without
forwarding any props, unlike the ScrollView mock which spreads
`{...this.props}`. This makes props like `testID`, `onRefresh`,
and `accessibilityLabel` invisible to testing library queries,
forcing workarounds like `UNSAFE_getByType`.
@psjostrom psjostrom force-pushed the fix/refreshcontrol-mock-forward-props branch from 7cb7a03 to 55608a1 Compare April 1, 2026 09:09
@meta-cla meta-cla 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 Apr 1, 2026
@facebook-github-tools facebook-github-tools bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Apr 1, 2026
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. 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.

1 participant