我试图单击一个<div>
元素,单击该元素将更改为<span>
元素。有一个呈现div元素的组件,并具有一个OnClick事件处理函数,该事件处理函数触发引发此更改的函数。现在,我通过渲染带有硬编码道具的组件来编写单元测试。但是,在模拟点击时,呈现的DOM根本不会改变。
it('should do something' () => {
baseProps.prop1 = true;
let myObject = new myComponent(baseProps);
let component = ReactTestUtils.renderIntoDocument(myObject.render());
let renderedDOM = ReactDOM.findDOMNode(component as React.ReactInstance) as HTMLElement;
let RadioWithFillin: HTMLButtonElement = renderedDOM.getElementsByClassName('class_name')[0] as HTMLButtonElement;
console.log(renderedDOM);
ReactTestUtils.Simulate.click(RadioWithFillin);
console.log(renderedDOM);
});
renderedDOM应该添加一个新的span元素,但是没有发生。知道出什么事了吗?