-
Notifications
You must be signed in to change notification settings - Fork 44
feat: support @testing-library/react-native 7.0 #50
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
Conversation
0accbc4
to
6978fcb
Compare
Codecov Report
@@ Coverage Diff @@
## master #50 +/- ##
===========================================
- Coverage 100.00% 96.34% -3.66%
===========================================
Files 8 8
Lines 96 82 -14
Branches 28 26 -2
===========================================
- Hits 96 79 -17
- Misses 0 1 +1
- Partials 0 2 +2
Continue to review full report at Codecov.
|
Um, I don't see why would we remove the feature to add it once again? Maybe we could extract some helpers from RNTL that could be used by |
@thymikee sorry for taking too long to answer. |
Is there still work being done on this? We'd really like to be able to use |
6978fcb
to
2835556
Compare
2835556
to
1f1bda8
Compare
@thymikee @mdjastrzebski after some months I'm finally back to this PR. sorry for that. I have some questions:
|
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.
I've added some thoughts about the tests and vague idea about the implementation, these might be relevant but might be not because I haven't worked with RNTL internals lately.
|
||
export function toBeDisabled(element) { | ||
checkReactElement(element, toBeDisabled, this); | ||
|
||
const isDisabled = isElementDisabled(element) || isAncestorDisabled(element); | ||
const isDisabled = !(element.props?.onStartShouldSetResponder?.() ?? true); |
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.
In my opinion we should mimic the current RNTL 7.2 logic here: isEventEnabled
function & it's deps. Potentially the check might have to be recursive as fireEvent
implementation in RNTL is performing recursive checks.
test.each([ | ||
['Button', Button, { title: 'some button' }], | ||
['TouchableOpacity', TouchableOpacity, {}], | ||
['TouchableHighlight', TouchableHighlight, {}], | ||
['TouchableWithoutFeedback', TouchableWithoutFeedback, {}], | ||
['TouchableNativeFeedback', TouchableNativeFeedback, {}], | ||
['Pressable', Pressable, {}], | ||
])('handles disabled prop for %s', (_, Component, props) => { | ||
const { queryByTestId } = render( | ||
<Component disabled testID="touchable" {...props}> | ||
<View /> | ||
</Component>, | ||
); | ||
|
||
expect(queryByTestId('touchable')).toBeDisabled(); |
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.
test.each([ | |
['Button', Button, { title: 'some button' }], | |
['TouchableOpacity', TouchableOpacity, {}], | |
['TouchableHighlight', TouchableHighlight, {}], | |
['TouchableWithoutFeedback', TouchableWithoutFeedback, {}], | |
['TouchableNativeFeedback', TouchableNativeFeedback, {}], | |
['Pressable', Pressable, {}], | |
])('handles disabled prop for %s', (_, Component, props) => { | |
const { queryByTestId } = render( | |
<Component disabled testID="touchable" {...props}> | |
<View /> | |
</Component>, | |
); | |
expect(queryByTestId('touchable')).toBeDisabled(); | |
test.each([ | |
['TouchableOpacity', TouchableOpacity, {}], | |
['TouchableHighlight', TouchableHighlight, {}], | |
['TouchableWithoutFeedback', TouchableWithoutFeedback, {}], | |
['TouchableNativeFeedback', TouchableNativeFeedback, {}], | |
['Pressable', Pressable, {}], | |
])('handles disabled prop for %s', (_, Component, props) => { | |
const { getByText, getByTestId } = render( | |
<Component disabled testID="touchable" {...props}> | |
<Text>Trigger</Text> | |
</Component>, | |
); | |
expect(getByText('Trigger')).toBeDisabled(); | |
expect(getByTestId('touchable')).toBeDisabled(); |
I think that we should assume that there is a certain duality between RNTL fireEvent
and toBeDisabled
, if fireEvent
calls and event handler then toBeDisabled
should be false, and vice-versa (obviously except the case when there is no event handler defined). So if RNTL users frequently use things like getByText
to find button with given text, we should also support calling toBeDisabled()
on that getByText
result.
@brunohkbx @thymikee Wdyt? Does it make sense? (my RNTL expertise got little rusty lately)
NB: Button
is excluded because it uses title prop and didn't want to mix it with child element. We can test it separately if needed.
expect(queryByTestId(name)).toBeDisabled(); | ||
expect(() => expect(queryByTestId(name)).not.toBeDisabled()).toThrowError(); | ||
}); | ||
test.each([ |
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.
We probably want to test the opposite case as well (not.toBeDisabled()
when there is no disabled
prop).
This PR is out of sync with @brunohkbx would you have time and will to re-examine the PR and rebase/reimplement the relevant parts with the current codebase? |
Closing as stale. Things have move a lot since this PR has been create. @brunohkbx We might restart this effort in a fresh PR, based on current codebase, if you still see value in it. |
Rewrite toBeDisabled asserting the logic RN does around
onStartShouldSetResponder
as discussed in #23docs
Resolves #43