我试图嘲弄模块附带反应母语(没有第三方模块),如LayoutAnimation
:如何嘲笑反应,本机模块(没有第三方模块)与笑话
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是否意识到反应原生API? – rcorrie
在你的文件package.json中你有这个:'“jest”:{“preset”:“react-native”}'。所以是的,jest知道反应原生API –