我正在使用React-native开发示例应用程序。我使用Jest来使用单元测试,我对Jest Api调用没有任何想法 我想在不使用Promise的情况下需要: 这是我的代码:
这是我的功能代码:
/**
* @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);
});
最后这是我的代码请。在此先感谢