如何用jest模拟react-native模块(不是第三方模块)
发布时间:2020-12-15 16:19:44 所属栏目:百科 来源:网络整理
导读:我试图模拟一个带有react-native(而不是第三方模块)的模块,例如LayoutAnimation: import * as RN from 'react-native'RN.LayoutAnimation = jest.fn() 但测试失败了: TypeError: Cannot read property 'decelerationRate' of undefined at Object.anonymou
我试图模拟一个带有react-native(而不是第三方模块)的模块,例如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.mock(‘LayoutAnimation’);
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |