我正在尝试为一个动画组件运行快照测试,该组件具有以下动画代码(在componentDidMount上调用):
animate() {
Animated.loop(
Animated.sequence([
Animated.timing(this.state.pulseAnimation, {
toValue: 1,
duration: 1000,
easing: Easing.in(Easing.ease)
})
]),
{
iterations: this.props.totalNumPulses
}
).start();
}
我尝试模拟以下动画:
jest.mock('Animated', () => {
return {
loop: jest.fn(() => {
return {
start: jest.fn(),
reset: jest.fn()
};
}),
timing: jest.fn(() => {
return {
start: jest.fn(),
};
}),
Value: jest.fn(() => {
return {
interpolate: jest.fn(),
};
}),
};
});
然而,运行测试会导致这个错误:
TypeError: animation.reset is not a function
54 | iterations: this.props.totalNumPulses
55 | }
> 56 | ).start();
57 | }
58 |
我已经在不同的位置放置了重置模拟,并检查了React Native中“loop”方法的源代码,但没有成功地模拟出来。有人之前成功地做到了吗?