简体   繁体   English

如何在Jest中测试React Native Button?

[英]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.

相关问题 如何使用 Jest 在 React Native 中测试屏幕道具 - How to test screenprops in react native using Jest 如何在玩笑中使用 NavigationEvents 测试 React Native 组件 - How to test React Native component with NavigationEvents in jest 如何测试使用Jest导入自定义本机模块的React Native组件? - How to test a React Native component that imports a custom native module with Jest? 如何使用Jest,Enzyme for React-Native模拟单元测试中的事件 - How to simulate an event on a unit test with Jest, Enzyme for React-Native 如何测试React Native Button的模拟? - How to test React Native Button's simulate? 用 jest 和 react-native-firebase 进行测试 - Test with jest and react-native-firebase 单元测试使用带有Jest的Native Modules的React Native应用程序 - Unit test React Native app that uses Native Modules with Jest 如何使用酶玩笑为 React Native 中的导航堆栈编写单元测试用例? - How to write unit test cases for navigation stack in react native using enzyme jest? 如何使用 Jest 在 react-native 中使用模拟 fetch() 对 API 调用进行单元测试 - How to unit test API calls with mocked fetch() in react-native with Jest React Native Jest - 如何使用多个钩子测试功能组件? 无法存根 AccessiblityInfo 模块 - React Native Jest - How to test Functional component with multiple hooks? Unable to stub AccessiblityInfo module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM