I am trying to mock a module that ships with react-native (not 3rd party modules), such as LayoutAnimation
:
import * as RN from 'react-native'
RN.LayoutAnimation = jest.fn()
But the test fails with:
TypeError: Cannot read property 'decelerationRate' of undefined
at Object.<anonymous> (node_modules/react-native/Libraries/Components/WebView/WebView.ios.js:555:3254)
at Object.get WebView [as WebView] (node_modules/react-native/Libraries/react-native/react-native-implementation.js:73:22)
Is there any other way to mock/stub out a RN module such as LayoutAnimation
or any other react-native (not 3rd party) module?
Setup Run yarn test to run tests with Jest. If you are upgrading your react-native application and previously used the jest-react-native preset, remove the dependency from your package. json file and change the preset to react-native instead.
Try to simply do jest.mock('LayoutAnimation');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With