我进行了以下测试:
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({})
})
第一个期望通过的地方,但第二个没有得到以下指示的地方:
测试将失败,因为我正在针对空对象进行检查,但是我希望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,
})
}