[英]How to test screenprops in react native using Jest
I have a class that extends from Component in my React Native project.我的 React Native 项目中有一个从Component扩展的类。 I use this class in other classes render and I pass screen props with it:我在其他类渲染中使用这个类,并用它传递屏幕道具:
class OtherClass extend Component {
render() {
return (
<MyCustomComponent screenprops ={{number : this.state.number}}
})
}
Now I am using Jest to write tests.现在我正在使用 Jest 编写测试。 I was able to write a test for the component class without the screen props:我能够在没有屏幕道具的情况下为组件类编写测试:
test('MyCustomComponent renders correctly', () => {
renderer.create(this.MyCustomComponent);
});
But I don't know how test the screenprops and use them in my test.但我不知道如何测试 screenprops 并在我的测试中使用它们。 I've search a lot but I couldn't find a solution.我已经搜索了很多,但我找不到解决方案。
you can do it like this :你可以这样做:
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.