我一直在尝试运行单元测试,但我不断收到此错误:
TypeError: ShallowWrapper::state("isOpen") 要求state
not be null
or undefined
我见过类似的东西并且能够修复它 - 但我目前不知道哪里出了问题
使用 React JS - JEST 和 ENZYME
here is the main file js
closeModal = () => {
//If close qfmodal, set modalvalues back to values
let quickfilterModalValues =
Object.assign({},this.state.quickfilterValues);
this.setState({
selectedRecon_UID: null,
refreshModalOpen: false,
descriptionModalOpen: false,
quickFilterModalOpen: false,
<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>
Here is the file.test.js
我没有在这里包含描述和 beforeEach() 测试 -
// defining this.props
const baseProps = {
onClick,
isOpen:false,
}
it("renders a modal portal", () => {
const isOpen = wrapper.state("isOpen");
const modalPortal = wrapper.find("div.fullmodal");
expect(isOpen).toBeTruthy;
expect(modalPortal).toHaveLength(1);
expect(toJson(wrapper)).toMatchSnapshot();
});
我希望我的快照也能呈现 MODAL