我的代码中有许多动画,它们是根据相同的FlatList
onScroll
生成的相同animationRange产生的。它们都按预期工作,但是我需要在调用动画的位置添加测试覆盖率。不幸的是,我不知道如何模拟animationRange。
我曾尝试用以下方式嘲笑animationRange
:
const mockInterpolation = jest.fn();
const mockAnimationRange = jest.fn().mockImplementation(() => {
return { interpolate: mockInterpolation }
});
但是它只是在测试时返回错误,我有信心这仅仅是因为我不知道如何正确模拟该值。
Here is the Flatlist that sets the animationRange
--------------------
<FlatList
onScroll={Animated.event([{
nativeEvent: { contentOffset: { y: animationRange } },
}],
{
useNativeDriver: true,
})}
/>
这个animationRange
值似乎是我需要嘲笑的。并且需要能够处理以下内容:
export const AnimateScore = (animationRange) => {
return {
transform: [
{
translateX: animationRange.interpolate({
inputRange: [0, (100)],
outputRange: [0, screenWidth * 0.125)],
extrapolate: 'clamp',
}),
},
],
};
};
我所寻找的只是模拟此值或测试.interpolate
的{{1}}偏移值的正确方法。
谢谢。