From 00f074f38b6f2e92fc26f895c28aeae79aa3764c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= <63123542+m-bert@users.noreply.github.com> Date: Wed, 21 Aug 2024 09:02:39 +0200 Subject: [PATCH] Fix `inline style` tests in `Jest` (#6400) ## Summary It was brought to our attention that `inline styles` do not work with `Jest`. This PR aims to fix this problem. ## Test plan Run tests --- .../__tests__/hooks.useAnimatedStyle.test.tsx | 91 ++++++++ .../__tests__/inlineStyles.test.tsx | 197 ++++++++++++++++++ packages/react-native-reanimated/package.json | 2 +- .../createAnimatedComponent/commonTypes.ts | 1 + .../createAnimatedComponent.tsx | 17 +- .../react-native-reanimated/src/jestUtils.ts | 57 ++++- yarn.lock | 24 ++- 7 files changed, 374 insertions(+), 15 deletions(-) create mode 100644 packages/react-native-reanimated/__tests__/hooks.useAnimatedStyle.test.tsx create mode 100644 packages/react-native-reanimated/__tests__/inlineStyles.test.tsx diff --git a/packages/react-native-reanimated/__tests__/hooks.useAnimatedStyle.test.tsx b/packages/react-native-reanimated/__tests__/hooks.useAnimatedStyle.test.tsx new file mode 100644 index 00000000000..edb18da0e2c --- /dev/null +++ b/packages/react-native-reanimated/__tests__/hooks.useAnimatedStyle.test.tsx @@ -0,0 +1,91 @@ +import { Button, View } from 'react-native'; +import { fireEvent, render, screen } from '@testing-library/react-native'; +import Animated, { + useSharedValue, + getAnimatedStyle, + useAnimatedStyle, + withTiming, +} from '../src'; + +jest.useFakeTimers(); + +describe('Tests of inline styles', () => { + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.runOnlyPendingTimers(); + jest.useRealTimers(); + }); + + test('useAnimatedStyle', () => { + function UseAnimatedStyle() { + const width = useSharedValue(100); + + const handlePress = () => { + width.value = width.value + 50; + }; + + const animatedStyle = useAnimatedStyle(() => { + return { + width: width.value, + }; + }, [width]); + + return ( + + +