question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot check if an element is disabled after updating to v7

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
JoseLioncommented, Sep 8, 2020

@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:

export function isDisabled(element: Nullable<ReactTestInstance>): boolean {
  return !!element?.props.onStartShouldSetResponder?.testOnly_pressabilityConfig()?.disabled;
}

Then in a spec

expect(isDisabled(getByText("Cancel")).toEqual(false);

expect(isDisabled(getByText("Continue")).toEqual(true);
4reactions
JoseLioncommented, Oct 24, 2020

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 😀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found