2016-01-29 134 views
1

我試圖測試深度嵌套組件的功能,但在「選擇」Simulate時遇到問題。React組件兒童測試

我一直在逼近這個問題的方法是使用下面的:

const component = renderIntoDocument(TestParent); 
const dropdown = findRenderedComponentWithType(component, TimespanDropdown); 
const buttons = scryRenderedDOMComponentsWithTag(dropdown, 'button'); 
Simulate.click(buttons[0]); 

這分崩離析,當我通過下拉列表srcyRenderedDOMComponentsWithTag。我可以添加一個類到我的按鈕,也許使用scryRenderedDOMComponentsWithClass,但我寧願看看是否有辦法以某種方式「鏈接」這些util查找調用。你可以簡化這一系列電話

+0

哪個版本陣營您使用的? –

+0

版本是0.14.3 – paulruescher

回答

0

一種方法是你的根組件上使用ReactDOM.findDOMNode,然後使用querySelector直接進入你關心的元素:

const component = ReactDOM.findDOMNode(renderIntoDocument(TestParent)); 
const buttons = component.querySelector('button'); 
Simulate.click(buttons[0]);