Я разрабатываю пример приложения на React-native.Я использовал Jest для использования модульного тестирования, у меня нет представления о вызове Jest Api, который мне нужен без использования Promises: вот мой код:
это мой код функции:
/**
* @description - Действие для вызова службы nilpick при успешном маршруте приращения, а также для отметки местоположения как выполненного * /
function nilPick() {
return async (dispatch, getState) => {
const currentState = getState();
const {user, picking} = currentState;
const {currentRouteIndex, pickRoute} = getState().picking.pickRouteInfo;
const { workId } = picking.pickWorkInfo;
const nilPickItem = pickRoute[currentRouteIndex];
const currentItem = getCurrentItem(currentState);
const currentTime = dateFunctions.getCurrentUTC();
const nilpickedItem = [{
"orderId": nilPickItem.fulfillOrdNbr,
"lineNbr": nilPickItem.ordLine,
"pickUpcNbr": nilPickItem.upc,
"pickDisplayTs": currentTime,
"pickUom": currentItem.workDetail.uom,
"pickedLoc": nilPickItem.location,
"locationType": nilPickItem.locType,
"locId": nilPickItem.locId,
"pickByType": currentItem.workDetail.pickByType,
"exceptionPick": false,
"gtinPrefRankNbr": 0,
"pickUpcTypeCd": 5100,
}];
const {status, statusText} = await pickingService.nilPick(nilpickedItem, user, workId);
if (status === 200 || statusText === 'Created') {
console.info("Item nilpicked");
if (currentRouteIndex < pickRoute.length) {
dispatch(incrementRoute());
} else {
Alert.alert(
'Nilpick Complete',
[
{
text: 'OK', onPress: () => {
dispatch(endPicking())
}
},
],
{cancelable: false},
);
console.log("End of pickwalk");
return;
}
}
else {
console.info("error in nilpicking item ");
}
}
}
This is my code above method to Converting Like this below sample test Case:
This is sample Test i want to call Api How to implement in Jest
it('Test For nillPic', () => {
let initialState = {picking: {pickRouteInfo:{
fulfillOrdNbr: pickRouteInfo.fulfillOrdNbr,
orderLine: '1',
upc: '4155405089',
location: 'A-1-1',
availableLocsToPick: '2',
'suggSubPendingPicks?': 'N',
'manualSubPendingPicks?': 'N',
lineFullfilled: 'false',
currentRouteIndex: 1,
pickRoute: ['r1', 'r2', 'r3']
}}};
//console.log("state data...", initialState);
const store = mockStore(initialState);
store.dispatch(actions.pickRouteActions.nilPickSuccess());
const expectedAction = [{"type": "INCREMENT_ROUTE"}] ;
const localActions = store.getActions();
expect(localActions).toEqual(expectedAction);
});
Наконец, это мой код Пожалуйста.Заранее спасибо