Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to write unit test for a React Native component returning ListItem and having multiple props. I'm struggling to do so. Any suggestions?

$
0
0

I'm a fresher and got a task of writing unit test for the following component. The problem is there are multiple props and some condition as well based on which I need to show the toggle.I am not understanding how to test that? Whether by passing dummy data or how?

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>);};

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>