问题描述
export const SelectedItem: React.FC<SelectedItemProps> = ({
inputStyle,item,...rest
}) => {
return (
<Input
{...rest}
value={item?.name}
placeholder='Seleccione ciudad...'
editable={false}
containerStyle={!item && inputStyle}
/>
);
};
当我用Jest做测试时,我在哪里:
const rendered = render((
<SelectedItem
testID='input'
item={undefined}
inputStyle={[{ borderColor: 'red' }]}
/>
));
const input = rendered.getByTestId('input');
console.log('input.props: ',input.props);
在console.log中,我可以看到:
{
allowFontScaling: true,rejectResponderTermination: true,underlineColorAndroid: 'transparent',testID: 'input',editable: false,placeholder: 'Seleccione ciudad...',style: {
alignSelf: 'center',color: 'black',fontSize: 18,flex: 1,minHeight: 40
},children: undefined
}
为什么placeholder
,editable
和value
道具在那里而不是containerStyle
?
我需要containerStyle
,因为我需要测试该道具是否通过。该测试有效:
expect(input.props.value).toBe('bar');
expect(input.props.editable).toBe(false);
expect(input.props.placeholder).toBeTruthy();
但是无法测试我想要的道具。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)