模态组件-onClick事件

时间:2019-04-02 15:24:49

标签: reactjs jestjs enzyme

尝试测试以下点击事件:将Jest和Enzyme用于ReactJS

<Modal isOpen={this.state.descriptionModalOpen} style={descriptionModalStyle}>
  <div>
   <div className='fullmodal'>
   <div className="fullmodal_title">
     <div className="fullmodal_title_add">Description</div>
   </div>             
   <div className='sidemodal_addnew_x' id="close-Modal-id" onClick={this.closeModal}>
     <FontAwesome name='xbutton' className='fa-times' />
    </div>
    </div>    
   {this.getDescription()}
      </div>
    </Modal>

找不到节点。其他点击事件测试通过得很好,但这是Modal中唯一的事件。

这是我测试文件的一部分

 beforeEach(() => (wrapper = mount(<MemoryRouter keyLength={0}><Notifications {...baseProps} /></MemoryRouter>)));

it("should check  button click events under  Modal Component", () => {
baseProps.onClick.mockClear();
wrapper.find('Notifications').setState({
  descriptionModalOpen: false,

});
wrapper.update() 
wrapper.find('Notifications').find('#close-Modal-id').simulate("click"); 
});

1 个答案:

答案 0 :(得分:1)

您尝试在哪里找到吗?

const yourElement = element.findWhere(node => node.id === "close-Modal-id")
yourElement.simulate('click');

如果没有,您是否可以验证findWhere是否遍历了您要定位的节点?

相关问题