error : ReactWrapper::state(“isOpen”) requires that `state` not be `null` or `undefined`

断了今生、忘了曾经 提交于 2019-12-20 06:13:48

问题


Writing an unit test file and not able to Render Modal components. I am using jest and Enzyme REACTJS

Here is what I have used in previous files for testing

   describe("Component Test", () => {

beforeEach(() => (wrapper = mount(<BrowserRouter><Component{...baseProps} /></BrowserRouter>)));

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

});

here is an example of render() with a Modal component

         <Modal isOpen={this.state.quickFilterModalOpen} style={descriptionModalStyle}>
      <div>
        <div className='fullmodal'>
          <div className='sidemodal_addnew_x' onClick={this.closeModal}>
            <FontAwesome name='xbutton' className='fa-times' />
          </div>
        </div>    

error: ReactWrapper::state("isOpen") requires that state not be null or undefined.

Goal is to be able to render Modal components

来源:https://stackoverflow.com/questions/54889810/error-reactwrapperstateisopen-requires-that-state-not-be-null-or-un

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