mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
fix: toBeVisible edge case for style values (#1640)
This commit is contained in:
committed by
GitHub
parent
2f4568a29b
commit
be31579991
@@ -254,3 +254,12 @@ test('toBeVisible() on non-React elements', () => {
|
||||
Received has value: true"
|
||||
`);
|
||||
});
|
||||
|
||||
test('toBeVisible() does not throw on invalid style', () => {
|
||||
// @ts-expect-error: intentionally passing invalid style to
|
||||
// trigger StyleSheet.flatten() returning undefined.
|
||||
render(<View testID="view" style={0} />);
|
||||
|
||||
const view = screen.getByTestId('view');
|
||||
expect(view).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -54,7 +54,6 @@ function isElementVisible(
|
||||
}
|
||||
|
||||
function isHiddenForStyles(element: ReactTestInstance) {
|
||||
const style = element.props.style ?? {};
|
||||
const { display, opacity } = StyleSheet.flatten(style);
|
||||
return display === 'none' || opacity === 0;
|
||||
const flatStyle = StyleSheet.flatten(element.props.style);
|
||||
return flatStyle?.display === 'none' || flatStyle?.opacity === 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user