我一直试图使用酶浅渲染来模拟onPress . 但是由于react-intl,我无法访问TouchableOpacity
我已经看到了将intl注入反应组件的辅助函数,但这些函数似乎只适用于React而不是反应本机 .
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会成为解决这个问题的方法吗?
1 回答
这种方法帮助我避免使用IntlProvider包装我的组件 .
How can I test react-native component with mocha + enzyme + chai when it's wrapped in a Provider component
我能够使用.dive()和.instance()遍历所需的组件
希望这有助于其他人处理同样的问题 .