我已经为组件中的功能编写了一个测试方案,该方案处理的是单击按钮。在运行测试时,出现错误
**Error Config not loaded thrown**
这是我的测试用例
it('should dispatch handleForwardTranslation', (done) => {
const mockStore = configureMockStore();
const storeData = {
dispatch: () => {},
translator : initialState.translator
};
const store = mockStore(storeData);
const spy = jest.fn();
store.dispatch = spy;
const wrapper = shallow(<COAForwardTranslations store={store} />).dive();
wrapper.update();
wrapper.instance().handleForwardTranslation();
expect(spy);
done();
});
在容器中看起来像这样。我还有其他功能都可以正常工作,但是此特定功能似乎引发了错误。
class COAForwardTranslations extends Component
{
this.state = {
SegmentMapRequest : {
BranchCode: '',
GroupId: '',
GlCompanyCode: '',
GlAccount: '',
SourceMode: '',
SourceSystem: '',
JournalCategory: '',
EffectiveDate: ''
}
this.handleForwardTranslation = this.handleForwardTranslation.bind(this);
handleForwardTranslation()
{
this.props.getForwardTranslation(this.state.SegmentMapRequest);
}
render()
{
return(
<Button style ={{float:"right"}} bsStyle="primary" onClick={this.handleForwardTranslation}>Translate</Button>
)}
}
export const mapStateToProps =(state) =>({
segmentMapResponse: state.translator.segmentMapResponse
})
export const mapDispatchToProps = (dispatch)=>({
getForwardTranslation: (SegmentMapRequest)=>{
dispatch(getForwardTranslation(SegmentMapRequest));
}
})
export default connect(mapStateToProps,mapDispatchToProps)(COAForwardTranslations);