繁体   English   中英

如何使用 Jest 在 React Native 中测试屏幕道具

[英]How to test screenprops in react native using Jest

我的 React Native 项目中有一个从Component扩展的类。 我在其他类渲染中使用这个类,并用它传递屏幕道具

class OtherClass extend Component {

render() {
return (
         <MyCustomComponent screenprops ={{number : this.state.number}}
   })

}

现在我正在使用 Jest 编写测试。 我能够在没有屏幕道具的情况下为组件类编写测试:

test('MyCustomComponent renders correctly', () => {
  renderer.create(this.MyCustomComponent);
});

但我不知道如何测试 screenprops 并在我的测试中使用它们。 我已经搜索了很多,但我找不到解决方案。

你可以这样做:

test('renders correctly', () => {

  const propsLink = {
    screenProps: {
      arrayProp: [
        {
          v1: true,
          v2: "my value 1",
        },
        {
          v1: false,
          v2: "my value 2",
        }
      ],
      number: 1
    }
  }

  renderer.create(<MyCustomComponent {...propsLink} />)
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM