簡體   English   中英

TypeError:當我嘗試使用JEST測試方法時,dispatch不是函數

[英]TypeError: dispatch is not a function when I try to test a method using JEST

我有一個方法,該方法接收一些值作為參數,然后調度一個動作。 問題是,當我使組件變淺以測試此方法時,出現一個錯誤,指出dispatch不是函數。

測試:

test('it changes the state when submit is clicked', () => {
    const wrapper = shallow(<WizardForm store={store}/>);
    const values = {
    entrySign: 'archivoSign',
    signCertificateFile: 'file',
    signCertificate: 'text',
    entryAuth: 'notArchivoAuth',
    authCertificateFile: 'file',
    authCertificate: 'text'
}
const form = wrapper.instance();
//in this method I get the error
form.submit(values)

方法:

submit(values) {
  var authCertificate = this.checkAuth(values);
  var signCertificate = this.checkSign(values);
  let req = {
    authCertificate: authCertificate,
    signCertificate: signCertificate,
    userId: this.state.userId
  }
  const { dispatch } = this.props
  dispatch({type: 'CERTIFICATES_FETCH_REQUESTED', payload: {req}})
}

誰能幫我? 我不知道我在做什么錯。 提前致謝!

好吧,現在我有這個測試:

it('works', () => {
const values = {
  username: 'marc',
  name: 'marc',
  email: 'marc@hotmail.com',
  entrySign: 'archivoSign',
  signCertificateFile: 'file',
  signCertificate: 'text',
  entryAuth: 'notArchivoAuth',
  authCertificateFile: 'file',
  authCertificate: 'text'
} 
const mapDispatchToProps = (dispatch) => ({
  submit
});
const mockedStore = createMockStore();
const WizardFormWrapper = connect(reduxFormReducer, mapDispatchToProps)(WizardForm);
const wrapper = shallowWithStore(<WizardFormWrapper />, mockedStore);
   wrapper.props().submit();

});        
})

我現在遇到的問題是:ReferenceError:未定義提交任何建議@RIYAJ KHAN嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM