模态内部的onClick

时间:2019-04-04 13:12:14

标签: jestjs

试图弄清楚为什么模拟找不到节点。 尝试在Modal内部运行测试单击事件,但找不到节点 将Jest / Enzyme用于React JS

这是我设置状态的方式,系统权利是类名。 还执行以下操作:

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

  it("Test click event '", () => {
     baseProps.onClick.mockClear();
     wrapper.find('SystemEntitlements').setState({
       showSelectWarning:true,
       selectWarningModalOpen:false,   
       });
    console.log(wrapper.state())
    wrapper.find('SystemEntitlements').find('input[id="dontshow- testclick"]').simulate("click");

控制台日志返回NULL

这是file.js

 this.state.selectWarningModalOpen && 
 <Modal isOpen={this.state.selectWarningModalOpen} style={warningModalStyle}>
   <div>
     <div className='fullmodal'>
       <div className='sidemodal_addnew_x' onClick={this.closeModal}>
       <FontAwesome name='xbutton' className='fa-times' />
        </div>
        </div>   
          <div className='custom-ui'>
            <h1 className='confirm-entitlement-header'>Are you sure?</h1>
            <p className='confirm-entitlement-div'>This will update entitlements for this asset and may update the children of this asset</p>
            <div className='confirm-entitlement-div'>
             <div className='add-edit-button' id="closeModal-test-id" onClick={this.closeModal}>Cancel</div>
             <div className='add-edit-button' onClick={() => {
                this.handleChange(warningValue, warningRowIndex, warningColIndex, warningName)
                this.closeModal()
              }}>Continue</div>
           </div>
           <div className='confirm-entitlement-div'>
          <label>Do not show this message again</label>
            <input className='stop-message-checkbox' id='stop-message-checkbox' type='checkbox' checked={!this.state.showSelectWarning} onClick={() => {this.setState({showSelectWarning: !this.state.showSelectWarning})} } />
          </div>
        </div>
       </div>
    </Modal>

0 个答案:

没有答案