Jest: How can I mock out Animated loops?
The issue in your example is that you are completely replacing Animated
with an object, rather than only replacing the methods you need to test.
In the example below, I mock out parallel().start(callback)
so that it immediately invokes the callback.
// Tests/__mocks__/react-native.js
export const Animated = {
...RN.Animated,
parallel: () => ({
// immediately invoke callback
start: (cb: () => void) => cb()
})
};
This allowed me to skip the animation and better test my start
callback. You can use a similar approach for any property or subproperty of Animated
!