-
Notifications
You must be signed in to change notification settings - Fork 43
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
toBeDisabled does not equal not.toBeEnabled #54
Comments
Well that was quite an embarrassing mistake to make in the title. |
Just spent an hour or two trying to figure out why my element isn't coming up as disabled. Finally decided to place some logs in this library and found the exact same oddity as @punksmurf . To be fank I don't think there is a right or wrong solution, there are cases when you want to check if a specific element is disabled (nested buttons) and cases where you want to check if the "whole branch" is disabled (non nested buttons). Same for enabled. BUT there is simply no reason for those two function to behave different from each other. I assume the best solution would be two separate assertions, e.g. For my (current) purposes I need the behavior of |
Looking at the documentation, Line 119 in 3cfd279
It does in fact not just check if the parent has been disabled, but the whole branch, up to the tree root, right? (I've not looked at the code for too long so don't blame me too hard.). But hey minor detail. On the other hand Line 147 in 3cfd279
This has the word similar in it, which means maybe this (rather important?) difference was supposed to be in the documentation? But only documenting it is not enough (IMO), people are going to assume and not look at it until it's too late. |
I was playing with the test code above by swapping
|
Same issue ...
|
@tomtanti Did you find any solution? In my case, I have a custom buttom based on a TouchableOpacity and both of the assertions are passing. toBeDisabled and toBeEnabled both are passing even if the button is disabled |
Fixed in #101 |
react-native
orexpo
: react-native@testing-library/react-native
version: 3.4.3jest-preset
: react-nativereact-native
version: 0.63.4node
version: v15.5.0Relevant code or config:
What you did:
Run this test.
What happened:
The second expectation fails, which I believe it should not do.
Reproduction:
I forked the template and made my changes (btw: the template is quite out of date, so I updated it to require the same versions as I run into this issue with).
The relevant file is here: https://github.com/Punksmurf/ntl-sample/blob/master/src/__tests__/App-test.js
Problem description:
As a user, I expect
toBeEnabled()
andtoBeDisabled()
to be opposites, and therefore I expect.toBeDisabled()
to yield the same result as.not.toBeEnabled()
. This however is not the case.I do not know if this is actually expected behaviour; the readme states that
toBeEnabled()
works similarly to.not.toBeDisabled()
. It should also be noted that it indeed does; it's the other way around that I think is problematic.The cause, as far as I can see, is in to-be-disabled.js:66. This differs from line 47 in that for the
toBeDisabled()
the ancestors are checked and fortoBeEnabled()
they are not.Suggested solution:
Changing to-be-disabled.js:66 to
var isEnabled = !(isElementDisabled(element) || isAncestorDisabled(element));
seems to fix the issue, however I am not comfortable recommending this change as I have almost no understanding of the internal workings of the testing library. Given thatisAncestorDisabled()
loops through quite a bit more ancestors (7) than I would expect (namely just the one), this is not just the view hierarchy and there may be subtleties at play that I do not know of.Can you help us fix this issue by submitting a pull request?
I could create a PR with the above mentioned solution, if that is indeed the fix.
The text was updated successfully, but these errors were encountered: