【发布时间】:2015-11-18 20:46:49
【问题描述】:
我目前正在测试 React 组件,组件的内联样式会根据不同的 props 值而改变。
这是我想做的一个例子:
let firstChild = TestUtils.findRenderedDOMComponentWithTag(renderedComponent, 'div');
expect(firstChild.getDOMNode().style).toEqual({
fontSize: '20px'
});
这是组件道具:
let renderedComponent = TestUtils.renderIntoDocument(
<CircleIcon
size="small" />
这是要测试的组件 dom:
return (
<div className="circle-icon" style={boxStyle}>
<span className={this.props.icon}></span>
</div>
);
如果我可以得到 boxStyle 里面的内容,我可以从中断言测试结果。
非常感谢!
【问题讨论】:
-
你试过了吗?你的结果是什么?
-
它现在可以工作了,只是有环境问题
标签: unit-testing reactjs jestjs reactjs-testutils