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