dimanche 18 octobre 2020

Condition coverage missing in Saga Test case

I have below line of code in Saga.js file. Not posting entire saga function but just the part of it where coverage is missing in my test. I have commented below which line coverage is missing in my test case.

const formData = yield call(constructApiData, modifyData) 
//constructApiData is function to modify the payload only. payload is `modifyData`

const response = yield call(postData, url, formData
// modified url formData is passed as payload for the post API call 

if(response.data.attributes.status === 'SUCCESS') { 
//COVERAGE MISSING FOR ABOVE LINE
yield put(saveRecommendations(response.data.attributes.recommendedPriorities));
yield call(onFormSubmitSuccess)
}

Here is the Saga.test.js file

expect(gen.next().value).toEqual(call(constructApiData, modifyData));
expect(gen.next(formData).value).toEqual(call(postData,'https://test.com', formData));

expect(gen.next(response).value).toEqual(put(saveRecommendations('priorities')))
expect(gen.next().value).toEqual(call(action.onFormSubmitSuccess));

How can i ensure i cover test coverage for this line in the saga.js file -> if(response.data.attributes.status === 'SUCCESS') {

Aucun commentaire:

Enregistrer un commentaire