超时-超时-jasmine.DEFAULT_TIMEOUT_INTERVAL内未调用异步回调

时间:2019-06-21 13:15:52

标签: javascript jestjs enzyme

尝试运行以下功能的测试:使用JEST和酶来反应JS

    async patchAccount() {
    const { user, services, FirmId } = this.props; 
    let StatusChanged = this.state.AccountStatus && (this.state.AccountStatus.value !== this.state.StartingStatus)
      let AccountBody = { 
        AccountName: this.state.AccountName,
        AccountTitle: this.state.AccountTitle,
      }
      if(StatusChanged) {
        AccountBody.AccountStatusDate = new Date().toISOString().slice(0, 19).concat('Z');
      }
      let response = await Models.patchAccount({ 
        user,
        services,
        body: AccountBody,
        firmId: FirmId,
        id: this.props.accountToEdit
        })
      if(!response.error) {
        return true;
      } else {
        return false;
      }  

这是我设置测试文件account.test.js

的方式
    it('Test patchAccount function ',async() => {
       jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000
      Models.postAccounts = jest.fn().mockImplementation(() => Promise.resolve(
       {error: false},
       {error: true},
       ))
      wrapper.setProps({
       user:{},
       services:[],
       FirmId:[],
       accountToEdit:[]
     })
     wrapper.find('AccountForm').setState({
       AccountBody:{},
       AccountStatus:""
     });
     wrapper.update();
     await expect(wrapper.find('AccountForm').instance().patchAccount()).toBeDefined()
    });

我该如何正确测试它并确保兑现承诺。还尝试使用HaveBeenCalled()调用模拟功能,但没有用。感谢您的帮助。

0 个答案:

没有答案