我的sagas文件如下:-
function* handleAPIs(request){
let response ;
try{
switch(request.params.type){
case "GET":
response = yield call(genericGetAPI,request.params.url);
yield put({type: HANDLE_STATE, stateValues: [{'key':request.params.responseStateVariable,'value':response}]});
response = yield call(genericGetAPI, url);
yield put({type: HANDLE_STATE, stateValues: [{'key':request.params.responseStateVariable,'value':response}]});
break;
case "POST":
response = yield call(genericPostAPI, {'fields':request.params.requestParams,'url':request.params.url});
yield put({type: HANDLE_STATE, stateValues: [{'key':request.params.responseStateVariable,'value':response}]});
break;
case "PUT":
response = yield call(genericPutAPI, {'fields':request.params.requestParams,'url':request.params.url});
yield put({type: HANDLE_STATE, stateValues: [{'key':request.params.responseStateVariable,'value':response}]});
break;
case "DELETE":
response = yield call(genericDeleteAPI,request.params.url);
yield put({type: HANDLE_STATE, stateValues: [{'key':request.params.responseStateVariable,'value':response}]});
break;
}
} catch (error) {
yield put({type: REQUEST_ERROR, error: error.message});
} finally {
yield put({type: SENDING_REQUEST, sending: false});
}
}
export function* handleAPI(){
yield takeEvery(HANDLE_API,handleAPIs);
}
我的Sagas测试文件如下:-
import { testSaga } from 'redux-saga-test-plan';
import {
HANDLE_API,
} from '../constants';
import { handleAPI } from '../sagas';
describe('Saga file testing', () => {
it('Handle API', () => {
testSaga(handleAPI)
.next()
.takeEvery(HANDLE_API)
.finish()
.isDone();
});
});
由于我不能使用handleAPIs传奇函数,因为它在导出中不存在。如何编写以下文件的测试用例? 我正在使用redux-saga-test-plan。