Cannot check if an element is disabled after updating to v7
See original GitHub issueDescribe the bug
In v6.0.0, I was able to check if an element had a disabled
prop like this: expect(element.props.disabled).toBeTruthy()
, but since I updated to v7.0.1, the disabled
attribute is no longer in the element.
Expected behavior
I would like to check if an element is disabled or not
Steps to Reproduce
Render a <TouchableOpacity disabled />
component and then try to check if it is disabled with expect(element.props.disabled).toBeTruthy()
Versions
@testing-library/react-native: ^7.0.1 => 7.0.1
react: ~16.11.0 => 16.11.0
react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Check that button is disabled in react-testing-library
Use data-test-id for <button> element; Select one of the ancestors of the <Click /> component and then select the button within(...) this scope ......
Read more >How to check a button is disabled using Cypress
I was looking for how to check if an element is enabled in order to determine the next actions. Make sure to include...
Read more >HTML attribute: disabled - HTML: HyperText Markup Language
The Boolean disabled attribute, when present, makes the element not mutable, focusable, or even submitted with the form.
Read more >How to disable or enable buttons using Javascript and jQuery
The function compares the value of the input field (the text field) with an empty string. 7. If the user has not typed...
Read more >Template type checking - Angular
Troubleshooting template errorslink · When a library's typings are wrong or incomplete (for example, missing null | undefined if the library was not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@thymikee that does not really solve the problem. Most of the time you’ll not be able to change the
onPress
prop for a spy because usually, we’d want to test buttons deep within a screen.As a workaround, I implemented a helper function that checks if
onStartShouldSetResponder
is implemented and has the pressablility config present:Then in a spec
While jest-native is great, we could not be using it on a project. We could not be even using Jest and testing with Mocha for instance (which is possible and fairly easy to achieve 😅).
IMHO, I think it’ll be better if this issue is addressed right from RNTL. I think this is not just an assertion convenience, it’s usually very important to tests that interactions are enable or disabled for a user 🙂
It’d be great if this issue can be reopened 😀