【发布时间】:2022-01-13 00:53:57
【问题描述】:
我目前正在尝试弄清楚如何使用 useSharedValue 测试恢复的 2 个动画。
对我来说 0 有意义的是 reanimated 中给出的例子。
https://github.com/software-mansion/react-native-reanimated/blob/master/tests/SharedValue.test.js
如果按钮应该在每次按下时将其 sharedValue 增加 1。你为什么要写一个测试表明它不会改变???
我自己试过了,是的,值不会自行更新。
我想断言我的测试中的值已经改变:
ParallaxScrollView.tsx
const scrollY = useSharedValue(0);
const onScroll = useAnimatedScrollHandler((event) => {
scrollY.value = event.contentOffset.y;
});
return (
<Animated.Image
style={{height: scrollY}}
testID="header-image"
source={{ uri: headerImage }}
resizeMode="cover"
/>
)
ParallaxScrollView.test.tsx
const { getByTestId } = render(<ParallaxScrollView {...defaultProps} />);
const headerImage = getByTestId('header-image');
const content = getByTestId('parallax-content');
const eventData = {
nativeEvent: {
contentOffset: {
y: 100,
},
},
};
fireEvent.scroll(content, eventData);
expect(headerImage).toHaveAnimatedStyle({ height: 100 }); //Received is 0
【问题讨论】:
标签: react-native jestjs react-native-reanimated react-native-testing-library