【发布时间】:2018-03-06 15:39:13
【问题描述】:
几天前我开始使用 Jest,我试图获得 100% 的覆盖率,但我有一个简单的问题,我无法解决。
这是 Jest Coverage 的示例
File |% Stmts |% Branch |% Funcs | % Lines | Uncovered Line #s |
src/lib | 66.67 | 0 | 10 | 100 | |
theme.js | 66.67 | 0 | 10 | 100 | 64,81 |
因此,我找到了第 64 行和第 81 行。这里是 styled-components 的简单函数。
export const fontSize = (fontSize, lineHeight) => (`
font-size: ${fontSize}px;
line-height: ${lineHeight ? `${lineHeight}px` : '1.1'}; // that's 64
`);
export const gradient = (gradType, gradDirection, gradStart, gradEnd) => (`
background: ${gradType}-gradient(${gradType === 'linear' ? gradDirection+',' : ''} ${gradStart}, ${gradEnd}); // that's 81
`);
如何测试它们?我试过了,但还是得到了 64 和 81 发现的信息。
const grad = {
gradType: 'linear',
gradDirection: 'toTop',
gradStart: '#000000',
gradEnd: '#ffffff',
};
expect(`background:${grad.gradType}-gradient(${grad.gradType === 'linear' ? grad.gradDirection+',' : ''}${grad.gradStart},${grad.gradEnd});`)
.toEqual(`background:linear-gradient(toTop,#000000,#ffffff`);`);
【问题讨论】:
标签: reactjs unit-testing jestjs