[英]How to unit test the state of props using mocha chai and enzyme?
我正在尝试对组件清晰显示中的道具状态进行onClick单元测试。
我尝试这样做:
props = {
attributeTableData: data,
clearMessage: onClickMethod,
reset: () => { },
resetAttributeTable: () => { },
statusMessage: {
messageType: 'message-success',
userMessage: 'Template has been saved successfully. Please wait …see your results display with the latest'
},
submitTemplateCreationStatus: () => { },
templateAttributeFormData: () => { },
templateFormSubmission: true,
templateAttributeFormSubmission: true,
templateFormData: () => { },
userRoles: new Set(['admin'])
};
let emptyStatusMessage = {};
actualComponent = shallow(<CreateTemplateResults { ...props } />);
actualComponent.instance().resetForms();
expect(onClickMethod.called).to.be.true;
expect(actualComponent.state('statusMessage')).to.eql(emptyStatusMessage)
但我得到:
“ TypeError:ShallowWrapper :: state(” statusMessage“)要求
state
不能为null
或undefined
”
您正在创建<CreateTemplateResults />
的浅表呈现器,但从未传递actualComponent.setState(nextState)
。 因此,当您尝试访问最后一行的状态时,由于state为null
/ undefined
,因此将引发错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.