ReactWrapper“要求状态不能为null或未定义

时间:2019-03-14 20:43:58

标签: reactjs jestjs enzyme

尝试渲染模态,但不断出现以下错误:

TypeError:ReactWrapper :: state(“ descriptionModalOpen”)要求state不是nullundefined

测试文件:我在其他文件中尝试了相同的方法,但效果很好

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();
});

});

这是Render()方法的一部分

 <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>

此处已设置状态:

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

0 个答案:

没有答案