开玩笑的预期行为测试失败

时间:2020-01-10 15:26:02

标签: javascript unit-testing redux

我进行了以下测试:

it('should handle searchForRepairs', async () => {

  await store.dispatch((searchForRepairs as any)(''))

  const state = {
    repairs: store.getActions().reduce(reducer, initialState)
  }

  expect(getRepairsProperty(state)).toMatchObject( 
    [{
      id: '',
      jobNo: '',
      trade: '',
      priority: '',
      status: '',
      raisedDate: '',
      appointmentDate: '',
      completedDate: '',
      description: '',
    }]
  )

  expect(store.getActions()).toEqual({})
})

第一个期望通过的地方,但第二个没有得到以下指示的地方:

enter image description here

测试将失败,因为我正在针对空对象进行检查,但是我希望store.getActions()中的操作类型包含在searchForReapirs中的await store.dispatch((searchForRepairs as any)(''))中。

我希望它会失败,因为{type: 'SOME_TYPE'}{}不同,它们基本上返回空值

searchForRepairs操作:

export const searchForRepairs = (searchTerm: string) => async (
  dispatch: Dispatch,
  getState: () => AppState
) => {
  if (!searchTerm) return

  dispatch({
    type: REPAIRS_SEARCH,
    // payload: { searchTerm },
  })

  const customerId = getCustomerId(getState())

  const propertyRepairs = await api.searchRepairs(`${customerId} AND ${searchTerm}`)

  dispatch({
    type: REPAIRS_SEARCH_SUCCESS,
    payload: propertyRepairs,
  })
}

0 个答案:

没有答案