【发布时间】:2015-03-21 13:45:21
【问题描述】:
我正在尝试为通过 react 组件呈现的一些 d3 元素编写测试,我希望能够挑选出页面上的一些 svg 元素并检查它们的宽度以查看它们是否正常运行正如预期的那样。
我不完全确定 react test-utils 文档在说 ReactComponent 树时会期待什么。
array scryRenderedDOMComponentsWithClass(ReactComponent tree, string className)
我正在通过以下方式将我的组件渲染到文档中:
var component = TestUtils.renderIntoDocument(
<ProgressCircle percentage={75} />
);
我可以通过以下方式成功检查 css className:
it('should render an element with the class "progress-circle"', function() {
var circleContainer = TestUtils.findRenderedDOMComponentWithClass(component, 'progress-circle');
expect(circleContainer).toBeDefined();
});
但我不明白我需要为其中一些需要 ReactComponent 树的 find / scry 方法提供什么。
http://facebook.github.io/react/docs/test-utils.html
编辑:
为了更清楚,这个组件的渲染 DOM 看起来像这样:
<div class="progress-circle">
<svg>
<g>
</g>
</svg>
</div>
...我正在寻找元素。
【问题讨论】: