ReactWrapper " Requires that state not be null or undefined

◇◆丶佛笑我妖孽 提交于 2019-12-13 04:16:09

问题


Trying to Render Modal but keep getting the following error:

TypeError: ReactWrapper::state("descriptionModalOpen") requires that state not be null or undefined

Test file : I have tried the same method in other files and it worked just fine

it("renders a modal portal", () => {
   const isOpen = wrapper.state("descriptionModalOpen");
   const modalPortal = wrapper.find(".fullmodal");
   expect(isOpen).toBeTruthy;
   expect(modalPortal).toHaveLength(1);
  expect(toJson(wrapper)).toMatchSnapshot();
});

});

Here is part of the Render() method

 <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' onClick={this.closeModal}>
            <FontAwesome name='xbutton' className='fa-times' />
          </div>
        </div>    
        {this.getDescription()}
      </div>
    </Modal>

Here is set state:

 let getINITIAL_STATE = (that) => {
return {
searchText: '',
filter: '',
loading: false,
editRecon: false,
descriptionModalOpen: false,

来源:https://stackoverflow.com/questions/55171666/reactwrapper-requires-that-state-not-be-null-or-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!