fix: toBeVisible edge case for style values (#1640)

This commit is contained in:
Maciej Jastrzebski
2024-07-26 09:32:22 +02:00
committed by GitHub
parent 2f4568a29b
commit be31579991
2 changed files with 11 additions and 3 deletions
@@ -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();
});
+2 -3
View File
@@ -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;
}