0
我一直在尝试模拟onPress使用酶浅呈现。 但是我无法访问TouchableOpacity由于反应国际测试使用enyzme浅和react-intl与反应原生
我见过的辅助函数注入intl到反应组件,但这些似乎只适用于反应,而不是反应本地。
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是否会成为这种情况?
我解决了我的问题。 这篇文章真的帮了我。 https://stackoverflow.com/questions/41649728/how-can-i-test-react-native-component-with-mocha-enzyme-chai-when-its-wrapp?rq=1 – Henry