Skip to content

cherry-pick(Reanimated): Guard for undefined style in Jest utils#8955

Merged
MatiPl01 merged 1 commit into4.2-stablefrom
@matipl01/cherry-pick/undefined-in-styles-array-jest
Feb 16, 2026
Merged

cherry-pick(Reanimated): Guard for undefined style in Jest utils#8955
MatiPl01 merged 1 commit into4.2-stablefrom
@matipl01/cherry-pick/undefined-in-styles-array-jest

Conversation

@MatiPl01
Copy link
Member

cherry-pick of the #8878

## Summary

When writing a component it's common to have undefined as a value in
array of styles. For example:

```tsx
interface Props {
  style?: ViewStyle
}

function MyComponent({ style }: Props) {
  const animatedStyles = useAnimatedStyles...

  return <Animated.View style={[style, animatedStyles]} />
}
```

Jest utils' getCurrentStyle will try to retrieve a value from undefined
resulting in:
```
TypeError: Cannot use 'in' operator to search for 'jestAnimatedValues' in undefined
```
## Test plan

```tsx
interface Props {
  style?: ViewStyle
}

function MyComponent({ style }: Props) {
  const animatedStyles = useAnimatedStyles(() => ({ width: '100%' }});

  return <Animated.View testID="my-component" style={[style, animatedStyles]} />
}
```

```tsx
it('Should ignore undefined in array of styles', () => {
   const { getByTestId } = render(<MyComponent />);
   expect(getByTestId("my-component")).toHaveAnimatedStyle({ width: '100%' });
   // passes without type errors
});
```
@MatiPl01 MatiPl01 self-assigned this Feb 12, 2026
@MatiPl01 MatiPl01 changed the base branch from main to 4.2-stable February 12, 2026 17:14
@MatiPl01 MatiPl01 merged commit a73f299 into 4.2-stable Feb 16, 2026
2 checks passed
@MatiPl01 MatiPl01 deleted the @matipl01/cherry-pick/undefined-in-styles-array-jest branch February 16, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants