【发布时间】:2016-06-01 06:12:10
【问题描述】:
只想使用Jest 和Enzyme 为我的react 组件实现单元测试。
有没有办法测试订单?假设我有组件 Button,我想同时渲染图标和文本。
当然最好为用户提供对齐选项(图标优先或儿童优先)。
Button.js
class Button extends React.Component {
constructor() {
super();
}
render() {
let content;
const icon = (<Icon type='search' />);
if (this.props.iconAlign === 'right') {
content = (<span>{this.props.children} {icon}</span>
} else {
content = (<span>{icon} {this.props.children}</span>
}
return (
<button>{content}</button>
);
}
}
如何使用 Jest 和 Enzyme 测试 iconAlign 道具?
【问题讨论】: