-
Notifications
You must be signed in to change notification settings - Fork 273
Cannot check if an element is disabled after updating to v7 #501
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
Comments
Can you provide a repro we can download? |
https://github.com/Covicake/react-native-issue run |
you can use |
That's the first thing that I tried but it doesn't work. The test passes using And also, I don't know why VS Code doesn't recognize those functions to be part of the expect. I added the 'extend-expect' thing to the jest.setup.js and it doesn't crash when I run the tests, so I don't know what else do I have to do to make the editor know of these functions |
@Covicake , You're right. Moreover, when i use Anyway there is already a open bug on jest-native --> testing-library/jest-native#23 Please also have a look there, if you haven't done it already 🙂 |
@pillu00 Alright, thanks for the info. Let's hope they fix it soon! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
To ensure that VSCode recognizes these functions as part of import "@testing-library/jest-native/extend-expect"; |
@Covicake if you check the <View
accessibilityLabel="test"
accessible={true}
focusable={false}
onClick={[Function onClick]}
onResponderGrant={[Function onResponderGrant]}
onResponderMove={[Function onResponderMove]}
onResponderRelease={[Function onResponderRelease]}
onResponderTerminate={[Function onResponderTerminate]}
onResponderTerminationRequest={[Function onResponderTerminationRequest]}
onStartShouldSetResponder={[Function onStartShouldSetResponder]}
style={
Object {
"opacity": 1,
}
}
/> you'll notice that the it("is disabled", () => {
const spy = jest.fn();
const { getByLabelText } = render(
<TouchableOpacity disabled accessibilityLabel="test" onPress={spy} />
);
fireEvent.press(getByLabelText("test"));
expect(spy).not.toHaveBeenCalled();
}); |
@thymikee that does not really solve the problem. Most of the time you'll not be able to change the As a workaround, I implemented a helper function that checks if 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); |
Yea, sounds like something to be included in |
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 😀 |
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, thedisabled
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 withexpect(element.props.disabled).toBeTruthy()
Versions
The text was updated successfully, but these errors were encountered: