-
-
Notifications
You must be signed in to change notification settings - Fork 992
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
Add testing-library
compatibility props
#3357
Changes from 7 commits
122d977
e51fdcd
9828131
930dabc
f1ac3ce
c63a561
556f8f2
f13e7b0
4d942e8
7a31f5e
6184078
4ec26c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -380,6 +380,10 @@ export default function Pressable(props: PressableProps) { | |||||||||
? children({ pressed: pressedState }) | ||||||||||
: children; | ||||||||||
|
||||||||||
// @ts-ignore Adding type definitions for @types/node causes multiple conflicts with react-native/types, | ||||||||||
// and as far as i know, there is no simple way of automatically resolving them. | ||||||||||
const inTestEnv = process.env.NODE_ENV === 'test'; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use this react-native-gesture-handler/src/utils.ts Lines 37 to 40 in 5b535c9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mentioned here: #3357 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. THis would tie the implementation only to Jest test runner. In case of user using other test runners Mocha, Vitest, Bun (not all of these are supported by RNTL atm) this props will not be set. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 4d942e8 |
||||||||||
|
||||||||||
return ( | ||||||||||
<GestureDetector gesture={gesture}> | ||||||||||
<NativeButton | ||||||||||
|
@@ -390,7 +394,10 @@ export default function Pressable(props: PressableProps) { | |||||||||
touchSoundDisabled={android_disableSound ?? undefined} | ||||||||||
rippleColor={processColor(android_ripple?.color ?? defaultRippleColor)} | ||||||||||
rippleRadius={android_ripple?.radius ?? undefined} | ||||||||||
style={[pointerStyle, styleProp]}> | ||||||||||
style={[pointerStyle, styleProp]} | ||||||||||
testOnly_onPress={inTestEnv ? onPress : undefined} | ||||||||||
testOnly_onPressIn={inTestEnv ? onPressIn : undefined} | ||||||||||
testOnly_onPressOut={inTestEnv ? onPressOut : undefined}> | ||||||||||
{childrenProp} | ||||||||||
{__DEV__ ? ( | ||||||||||
<PressabilityDebugView color="red" hitSlop={normalizedHitSlop} /> | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of argument should be passed to
testOnly_onPress
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testOnly_onPress
will currently always be of type((event: PressableEvent) => void) | null
, but this may change if more of our components will implementtestOnly_onPress
.I've made it of type
Function
, becauseRawButtonProps
usage is not specific toPressable
.Link to type definitions: (link)
Extract from type definitions: