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