У меня есть действие, которое имеет несколько отправлений в зависимости от статуса API.
Пуск> Успех | Сбой
Тестовый пример работал нормально с одной отправкой (УСПЕХ), но когда я изменил его и добавил к нему еще одну отправку. его ломается.
Action.js
export const getOrder = (orderNumber, requestMethod = request)=> {
return function (dispatch) {
dispatch({
type:ORDER.GET_ORDER_DETAIL_START
});
return requestMethod(apiServices.getOrderParams(orderNumber)).then(order=>{
const {success, message, data} = order.data;
const result = orderApiSignatureTransformer(data);
const payload = GlobalConfig.resultDto(success,message,result);
dispatch({
type:ORDER.GET_ORDER_DETAIL_SUCCESS,
payload
});
return payload
}).catch(()=>{
dispatch({
type:ORDER.GET_ORDER_DETAIL_FAILURE
});
})
}
}
Action.test.js
describe('ordersActions', ()=> {
it('should get an order for a given order number', () => {
const order = {
orderNumber: 111,
status: "OPEN",
dateUpdated: "01/01/2019"
}
const expectedActions = [
{ type: ORDER.GET_ORDER_DETAIL_START },
{ type: ORDER.GET_ORDER_DETAIL_FAILURE },
{ type: ORDER.GET_ORDER_DETAIL_SUCCESS, payload:order },
]
const store = mockStore({ orderDetail: [], orderDetailStatus: null });
const mockRequest = jest.fn(() => Promise.resolve(order));
return store.dispatch(getOrder(111, mockRequest)).then(() => {
// return of async actions
expect(store.getActions()).toEqual(expectedActions)
}).catch((e)=>{
expect(store.getActions()).toEqual(expectedActions)
})
})
})
Error
Ожидаемое значение равно:
[{"type": "GET_ORDER_DETAIL_START"}, {"type": "GET_ORDER_DETAIL_FAILURE"}, {"payload": {"dateUpdated": "01/01/2019", "orderNumber": 111, "status": "OPEN"}, "type": "GET_ORDER_DETAIL_SUCCESS"}]
Поступило:
[{"type": "GET_ORDER_DETAIL_START"}, {"type": "GET_ORDER_DETAIL_FAILURE"}]
Разница:
- Expected
+ Received
@@ -3,14 +3,6 @@
"type": "GET_ORDER_DETAIL_START",
},
Object {
"type": "GET_ORDER_DETAIL_FAILURE",
},
- Object {
- "payload": Object {
- "dateUpdated": "01/01/2019",
- "orderNumber": 111,
- "status": "OPEN",
- },
- "type": "GET_ORDER_DETAIL_SUCCESS",
- },
]
expect(store.getActions()).toEqual(expectedActions)
}).catch((e)=>{
expect(store.getActions()).toEqual(expectedActions)
})
})
})