【发布时间】:2017-10-30 08:05:04
【问题描述】:
我一直在尝试使用酶浅渲染来模拟 onPress。 但是由于 react-intl,我无法访问 TouchableOpacity
我已经看到了将 intl 注入到 react 组件中的辅助函数,但这些似乎只适用于 React 而不是 react-native。
it("should handle button presses", () => {
const onPress = sinon.spy();
const button = shallow(
<IntlProvider locale='en'>
<ButtonApprove
tintColor={STYLES.COLOR.BRAND_SUCCESS}
buttonStyle={{}}
containerStyle={{}}
handlePress={onPress}
/>
</IntlProvider>
);
// console.log(button.instance());
button.find(TouchableOpacity).simulate('press');
expect(onPress.calledOnce).toEqual(true);
});
JSdom 会是解决这个问题的方法吗?
【问题讨论】:
-
我已经解决了我的问题。这篇文章真的帮助了我。 stackoverflow.com/questions/41649728/…
标签: react-native enzyme react-intl