Fix RefreshControl jest mock to forward props#56301
Fix RefreshControl jest mock to forward props#56301psjostrom wants to merge 1 commit intofacebook:mainfrom
Conversation
|
Hi @psjostrom! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 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`.
7cb7a03 to
55608a1
Compare
Summary:
The
RefreshControljest mock renders<RCTRefreshControl />without forwarding any props. This is inconsistent with theScrollViewmock, which spreads{...this.props}to its native component.This has two consequences:
The rendered RefreshControl is invisible to RNTL host queries. Props like
testIDandaccessibilityLabelare not forwarded to the native component, sogetByTestId,getByLabelText, etc. cannot find it. The only way to locate it isUNSAFE_getByType.Props transformed internally by wrapper components are inaccessible. When a component wraps
RefreshControland transforms props before passing them down (e.g. wrappingonRefreshwith 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 withoutUNSAFE_getByType. The RNTL-recommended pattern oflist.props.refreshControl.props.onRefresh()only gives the original untransformed props from the React element descriptor.The fix spreads
this.propsontoRCTRefreshControlin both mock files, matching how the ScrollView mock already works. TheHostComponentgeneric is also updated from{}toRefreshControlPropsfor 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
RefreshControlwithtestID="my-control"produces:After this change:
This enables standard RNTL queries:
Instead of requiring: