[英]How to test React Native Button in Jest?
How could I test a press in react native? 我该如何测试新闻界对本机的反应? (react-native-elements) So the code I want to test is: (react-native-elements)所以我要测试的代码是:
<ListItem
containerStyle={styles.container}
titleContainerStyle={styles.title}
chevronColor={'#70be1d'}
rightIcon={{name:'check'}}
key={id}
title={name}
hideChevron={!checked}
onPress={ ()=>onMeasureRowPressed(id) }
/>
You can approach this in two different ways, direct or indirect. 您可以采用两种不同的方法来处理此问题,直接或间接。
direct: 直接:
const wrapper = shallow(< ListItem />);
const instance = wrapper.instance();
expect(wrapper.state('pressedRow')).toBe('');
instance.onMeasureRowPressed('1234');
expect(wrapper.state('pressedRow')).toBe('1234');
indirect: 间接:
const wrapper = shallow(<ListItem />);
expect(wrapper.state('pressedRow')).toBe('');
wrapper.find('ListItem').simulate('keyPress', {key: 'foo'});
expect(wrapper.state('pressedRow')).toBe('1234');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.