我试图模拟一个带有react-native(而不是第三方模块)的模块,例如LayoutAnimation: import * as RN from 'react-native'RN.LayoutAnimation = jest.fn() 但测试失败了: TypeError: Cannot read property 'decelerationRate' of
import * as RN from 'react-native' RN.LayoutAnimation = jest.fn()
但测试失败了:
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)
有没有其他方法可以模拟/存根RN模块,例如LayoutAnimation或任何其他反应原生(不是第三方)模块?
尝试简单地做jest.mock(‘LayoutAnimation’);