I am relatively new to react testing. Any help/advice is appreciated. I have this simple PencilIcon
component. I saw the test coverage report and the bold text below indicates that those bold text or lines of code are not covered in test coverage.
How do i ensure test coverage happens for those lines of text. Can someone point me how to write test cases for the bold text below.
I am not able to make the code bold. Basically this below line of code is not covered in test coverage report.
const classNames = getClasses({ styles, classes: ['pencilIcon'], className, brand })***
return (
And here is the full component
import React from 'react'
import { getClasses } from '../es/lib'
import SvgIcon from '../SvgIcon'
import styles from './PencilIcon.less'
const PencilIcon = ({ brand, className, ...keepProps }) => {
const classNames = getClasses({ styles, classes: ['pencilIcon'], className, brand })
return (
<SvgIcon {...keepProps} className={classNames} viewBox="0 0 44 44">
<path d="M18.999 31.396l-6.83 2.704a8.362 8.362 0 0 0-.868-1.026 8.535 8.535 0 0 0-1.438-1.148l2.74-6.924-1.208-1.209-5.127 12.954a.764.764 0 0 0 .16.826.764.764 0 0 0 .825.16l12.955-5.128-1.209-1.209zM36.949 11.929L32.07 7.051a2.87 2.87 0 0 0-2.029-.841c-.734 0-1.469.28-2.029.841l-15.8 15.803 8.937 8.937L33.56 19.377l3.39-3.39a2.869 2.869 0 0 0-.001-4.058zm-10.799.038l2.237 2.238L17.503 25.09l-2.237-2.236L26.15 11.967zm-5.002 16.768l-2.117-2.117 10.885-10.886 2.116 2.116-10.884 10.887z" />
</SvgIcon>
)
}
PencilIcon.defaultProps = {
title: 'Edit',
width: '44px',
height: '44px'
}
export default PencilIcon
And here is the getClasses
imported into above component.
export const getClasses = ({
styles = {},
classes = [],
className = '',
brand = '',
device = {}
}) => {
const classesInStyles = classes.concat([brand]).filter(_class => !!_class).map(name => styles[name]);
if (device.platform) {
classesInStyles.push(styles[device.platform === '7P' ? 'desktop' : 'mobile']);
device.keyboardOpen && classesInStyles.push(styles.keyboard);
}
return [...classesInStyles, className].join(' ').trim();
};
I suggest importing this line from a different file and excluding it from your test coverage.
<SvgIcon {...keepProps} className={classNames} viewBox="0 0 44 44">
<path d="M18.999 31.396l-6.83 2.704a8.362 8.362 0 0 0-.868-1.026 8.535 8.535 0 0 0-1.438-1.148l2.74-6.924-1.208-1.209-5.127 12.954a.764.764 0 0 0 .16.826.764.764 0 0 0 .825.16l12.955-5.128-1.209-1.209zM36.949 11.929L32.07 7.051a2.87 2.87 0 0 0-2.029-.841c-.734 0-1.469.28-2.029.841l-15.8 15.803 8.937 8.937L33.56 19.377l3.39-3.39a2.869 2.869 0 0 0-.001-4.058zm-10.799.038l2.237 2.238L17.503 25.09l-2.237-2.236L26.15 11.967zm-5.002 16.768l-2.117-2.117 10.885-10.886 2.116 2.116-10.884 10.887z" />
</SvgIcon>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.