reactjs - 三元运算符用 jest 测试用例
问题描述
我想为以下案例编写一个开玩笑的测试用例,因为它显示了分支覆盖率50%
并指出了这段代码。
render() {
const {
isExit
} = data;
const text = isExit ? 'Yes' : 'No';
或者
<LabelValue label="New Line" value={isExit ? 'Yes' : 'No'} />
测试用例
it('Should display the data if API status is complete', () => {
const wrapper = shallowWithTheme(<DataPage
orderDetail={{ isExit: true}}
theme={theme}
/>);
// what to write here?
});
解决方案
expect(wrapper.text()).to.equal('Yes');
expect(wrapper.text()).to.equal('No');
推荐阅读
- c++ - 使用 C++ 从磁卡读卡器 MT188 读取数据
- javascript - 为什么没有在反应中设置下拉菜单的初始值?
- javascript - 如何使用 setTimeout() 在 React 中使用 hooks 来加载状态?
- database - Flutter:尝试使用 OnTap 突出显示 ListTile
- botframework - 聊天机器人在模拟器和 Azure 门户中工作,但在网络聊天中无法正常启动
- python-3.x - Python - 在netCDF文件中将UTC更改为本地时间
- django - 如何调用范围内的变量值列表 | django
- java - 如何在 Hibernate 的同一张表上建模 ManyToOne 和 ManyToMany 关系?
- java - Java程序编译后无法正常运行
- python - Python从列表中删除大于阈值的元素