Vuex Action Jest测试:超时-未调用异步回调

时间:2020-05-06 14:24:58

标签: javascript unit-testing vue.js jestjs vuex

我在jest / vuex中进行测试时遇到了一些问题。

我正在尝试测试调用服务的异步操作,但这给了我一个超时错误。

快速笔记:我在jest-mock-axios各自的__mocks__文件夹中嘲笑import mockAxios from 'axios',并在测试文件顶部调用该嘲笑,例如:{{1} }。

这是动作:

async requestCases({ commit }, payload = {}) {
    try {
      const response = payload.params ? await getCases(payload.params) : await getCases()
      const { cases, metadata } = response
      commit(mutationTypes.setCases, { cases })
      commit(mutationTypes.setMetadata, { metadata })
      commit(mutationTypes.setTableRequestState, {params: payload.params})
    } catch (error) {
      commit(mutationTypes.setCasesError, error)
    }
  }

这是测试:

it('[action] requestCases', async () => {
    const commit = jest.fn()

    const payload = {
      PageNumber: 1,
      PageSize: 10,
      SearchQuery: '',
      SortColumn: 'patientname',
      SortDirection: 'desc'
    }

    await actions.requestCases({ commit }, payload)

    expect(mockAxios.get).toHaveBeenCalled()
    expect(commit).toHaveBeenCalled()
  })

这是错误:

Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error:

如您所见,这里没有什么特别的东西,我更改了超时等设置,但没有解决方法。有想法吗?

谢谢!

0 个答案:

没有答案