尝试渲染模态,但不断出现以下错误:
TypeError:ReactWrapper :: state(“ descriptionModalOpen”)要求state
不是null
或undefined
测试文件:我在其他文件中尝试了相同的方法,但效果很好
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,