reactjs - 如何为返回 ListItem 并具有多个道具的 React Native 组件编写单元测试。我正在努力这样做。有什么建议么?
问题描述
我是一个新人,我的任务是为以下组件编写单元测试。问题是有多个道具和一些条件以及基于我需要显示切换的一些条件。我不明白如何测试它?是否通过虚拟数据或如何传递?
type myProps = {
disabled?: boolean,
title?: string,
onClick: () => void | Promise<void>,
icon?: string,
text?: string,
icon2?: string,
toggleButton?: boolean,
value?: boolean,
onValueChange?: boolean,
thumbColor?: string,
trackColor?: string,
};
export const myList = ({
disabled = false,
title,
onClick,
icon1,
text,
icon2,
toggleButton,
value = false,
onValueChange = false,
thumbColor,
trackColor,
}: myProps) => {
return (
<ListItem onPress={onClick} disabled={disabled}>
{leftIcon && (
<Icon name={icon1} color={lightGray} style={styles.itemLeftIcon} size={IconSize} />
)}
<ListItem.Content>
<ListItem.Title>{title}</ListItem.Title>
</ListItem.Content>
{toggleButton ? (
<Switch
value={value}
onValueChange={onValueChange}
thumbColor={thumbColor}
trackColor={trackColor}
disabled={disabled}
/>
) : (
<Text style={styles.itemRightText} numberOfLines={2} ellipsizeMode={'tail'}>
{text}
</Text>
)}
{icon2 && (
<Icon name={icon2} color={lightGray} style={styles.itemRightIcon} size=
{IconSize} />
)}
</ListItem>
);
};
解决方案
推荐阅读
- java - Spring webflux Security - 使用属性禁用 csrf
- google-play - 如何更新 Google Play 控制台上正在审核的 App 的 App Bundle。我错误地上传了一个错误的 App Bundle,现在我想更新它
- calendar - 如何获取共享 O365 日历的 URL?
- git - 如果文件大小超过 26 MB,则无法以编程方式推送到 GIT 存储库
- android - DirectionsApiRequest 在 SDK 26 Android 手机下无法正常工作
- sql - 左连接与子查询
- html - 固定位置在 safari 上被切断
- python - 在我的 Knight's Move Python 程序中查找错误
- docker - 将时区参数传递给 gitlab 服务
- python - 如何将 Keras 转换为 Tensorflow Lite 并从另一种语言中使用?